Click here to Skip to main content
15,914,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In 1.aspx

C#
string[] _array = new string[2];
_array[0]="field 1";
_array[1]="field 2";
Response.Redirect("2.aspx?file=" + _array);


In 2.aspx

C#
string[] _array;
_array = (string[])Request.QueryString["file"];


error:
Cannot convert type 'string' to 'string[]'
Posted
Updated 6-Dec-11 23:01pm
v3
Comments
Sergey Alexandrovich Kryukov 7-Dec-11 5:03am    
What's not clear in the error message?
--SA

I think you cannot pass string[] directly through query string.
instead try with session variable like this..

In Page 1

C#
string[] _array = new string[2];
_array[0]="field 1";
_array[1]="field 2";
Session["StrArray"] = _array;
Response.Redirect("2.aspx");


In Page 2

C#
string[] strArray = (string[])(Session["StrArray"]);


Hope this helps..
 
Share this answer
 
In 2.aspx:

C#
string _string;
_string = (string)Request.QueryString["file"];


You are just pulling a string from the QueryString and not an array.

Regards,
Eduard
 
Share this answer
 
If you must do that, then you will need to convert the string array into a single string and convert it back when you are done. The most obvious way is to use a separator character that does not appear in your string ("|" perhaps) and combine the array elements into a single string . You can then use String.Split to convert the string back to an array later.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900