I have a File.aspx form where I display all the files.
When I upload a file I am using a upload.aspx file to run c# code to upload the file.
The thing is that at the end , I want to refresh the page automatically to display the new file upload but apparently it’s not redirecting even if all the parameters are good.
This is the code I use
HttpContext postedContext = HttpContext.Current;
string param = Request.UrlReferrer.Query;
string param2 = Request.UrlReferrer.Query;
var url = HttpUtility.ParseQueryString(param).Get("projectName");
var url2 = HttpUtility.ParseQueryString(param2).Get("projectId");
HttpPostedFile file = postedContext.Request.Files[0];
string name = file.FileName;
byte[] binaryWriteArray = new
byte[file.InputStream.Length];
file.InputStream.Read(binaryWriteArray, 0,
(int)file.InputStream.Length);
//FileStream objfilestream = new FileStream(Server.MapPath("~\\" + "\\Files\\" + url + "\\" + name), FileMode.Create, FileAccess.ReadWrite);
FileStream objfilestream = new FileStream(("C:\\inetpub\\wwwroot\\Clientportal\\Files\\" + url + "\\" + name), FileMode.Create, FileAccess.ReadWrite);
objfilestream.Write(binaryWriteArray, 0, binaryWriteArray.Length);
objfilestream.Close();
string[][] JaggedArray = new string[1][];
JaggedArray[0] = new string[] { "File was uploaded successfully" };
JavaScriptSerializer js = new JavaScriptSerializer();
string strJSON = js.Serialize(JaggedArray);
Response.Write(strJSON);
Response.Redirect(string.Format("Files.aspx?projectId={0}&projectName={1}", url2, url));
Any ideas ? I’m a bit stuck because I use this response.redirect everywhere and it works only when the code is in the same code file…
Maybe it’s because of the fact that I try to redirect from another code file ?
I would attempt to do reload on client side by using javascript:
if the JSON you get as a response contains message “File was uploaded successfully”
If you are not using ajax for submitting the file you don’t need to write json. It’s enough to redirect to the suitable url that contains a parameter that identifies status of file upload operation.