Reputation: 41
i hv postback event executing after i am trying to upload a file to server to ask for conformation by the user. after postback fileupload control gets cleared and i am not able to get its value after postback. controls viewstateEnabled property is true. How do i assign a file path to fileupload control after postback. I know its read only!!
please do reply...
Upvotes: 2
Views: 4955
Reputation: 41
use stream writer or contentbytes to copy the file to server in case of postback clearing fileupload control as fileupload control is read only control.
like this:
private void CreateFile()
{
// Create a file
FileStream newFile = new FileStream(Session["FileName"].ToString(), FileMode.Create);
// Write data to the file
byte[] Buffer = (byte[])ViewState["content"];
newFile.Write(Buffer, 0, Buffer.Length);
// Close file
newFile.Close();
}
Upvotes: 0
Reputation: 52241
Unfortunately You can't retain/assign value in FileUpload control. This is because of due to browser security reasons.
Upvotes: 1