Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i have FileUpLoad Control and Button control (UpLoadButton).I've facing problem like though FileUpLoad containg file path,it is showing null once after postBack or UpLoadButton clicked.

i've used following code:

protected void btn_UpLoadButton_Click(object sender, EventArgs e)
{

  if (FileUpload1.PostedFile.FileName!= null)//here is my doubt that showing Null Value though it's filled
  {
     HttpPostedFile File1 = FileUpload1.PostedFile;
     Data = new byte[File1.ContentLength];
     File1.InputStream.Read(Data, 0, File1.ContentLength);
     //  Session["ScannedPhotoData"] = Data;

     string strFilename = getFilename(FileUpload1.PostedFile.FileName);
     string strFilepath = "ImageFolder\\" + strFilename;
     string Photo = Server.MapPath(strFilepath);
     //if (File.Exists(Photo))
     //    File.Delete(Photo);
     FileUpload1.PostedFile.SaveAs(Photo);
     ImgScannedPhoto.ImageUrl = "imageview.aspx?img=" + Photo;
     //ScannedPhotoPath.Text = Photo;
  }
}

please reply thanks
Posted
Updated 22-Apr-11 2:53am
v2
Comments
jayantbramhankar 23-Apr-11 2:36am    
Are you using UpdatePanel on this Page?

You can't retain value in FileUpload control. This is because of security reasons. you can use RequiredFieldValidator for keyname textbox.
 
Share this answer
 
v3
Try saving the value to a session variable or a hidden field to preserve the data.Have a look at this article.

http://www.ironspeed.com/articles/Maintain%20File%20Upload%20Control/Article.aspx[^]
 
Share this answer
 
if (Fup1.HasFile)
{
    string FilePath = "";
    string[] a = new string[1];
    string fileName = "";
    string FullName = "";
    try
    {
        if (Fup1.FileName.Length > 0)
        {
            a = Fup1.FileName.Split('.');
            fileName = Convert.ToString(System.DateTime.Now.Ticks) + "." + a.GetValue(1).ToString();
            FilePath = Server.MapPath(@"~\FolderName");
            Fup1.SaveAs(FilePath + @"\" + fileName);

            FullName = FilePath + @"\" + fileName;
            // Database Save Operation of filename.

        }
    }
    catch
    {
    }
}



You can try with this.
If with this error is not solved then try,-

FileUploader.Atribute.add("Value",FileUploader.PostedFile); 

In PageLoad.

Hope this can help you.
 
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