开发者

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...


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


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();

        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜