views:

1081

answers:

4

Hi,

I have an application that works without any problem in a spanish server.

When i uploaded the application into the online server (an english windows), im getting exceptions (of type "input string is not a valid Datetime/Int32") with Convert.ToDateTime and Convert.ToInt32. Are any web.config line that could help me in this matter? I tried adding a globalization element with the Spanish culture, but didnt worked.

Could you give me a hand?

Thanks in advance. Josema.

+2  A: 

Are you specifying a CultureInfo argument, as an IFormatProvider in your String.Format() calls?

Mitch Wheat
+1  A: 

You might have set uiculture instead of culture in the globalization element, see: http://msdn.microsoft.com/en-us/library/bz9tc508.aspx.

...
    <globalization culture="es-MX" />
...

You can also try using a more specific culture (like the one above es - mexico).

Ps. I have a site working like that (actually with culture="en" as in my case I needed to force english as my development computer was configured with spanish at the time).

eglasius
I tried but didnt work.Thanks Freddy.
Josema
@Josema Try the variation with the more specific culture, specially given your scenario seemed to work when specifying it explicitely as in ck answer.
eglasius
A: 

Hi Mitch,

Yes, in the case of Datetime, im using "{0:d}".

Thanks a lot.

Josema
What I mean is, are you using a CultureInfo.InvariantCulture or similiar i String.Format ?
Mitch Wheat
Im using the property DataFormatString of a Autogenerated field in a datagrid this way:field.DataFormatString="{0:d}";Thats all.
Josema
+4  A: 

You need:

System.Globalization.CultureInfo culture = 
              new System.Globalization.CultureInfo("es-ES");
DateTime myDateTime = Convert.ToDateTime(string, culture);
ck
Hi ck, thanks for your fast answer, Are your lines the same than this?:1º Put in a web config the Spanish culture2º Datetime datetime=Convert.ToDatetime("01/2009");Thanks.Josema.
Josema
@Josema y, it will use the one in your web.config if you don't specify one explicitly.
eglasius
@Josema I assume this "Convert.ToDatetime("01/2009")" was just a typo and you have stuff like Convert.ToDateTime("31/01/2009")
eglasius