Akshay Pisal
Akshay Pisal

Reputation: 41

assign file to be uploaded path to fileUpload control after postback

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

Answers (2)

Akshay Pisal
Akshay Pisal

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

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

Unfortunately You can't retain/assign value in FileUpload control. This is because of due to browser security reasons.

Upvotes: 1

Related Questions