How to clear file upload text in server side (c#)

Murthy  picture Murthy · Dec 21, 2011 · Viewed 31.1k times · Source

I want to clear the file path from the file upload. The file upload is inside the update panel and I am using a AsyncFileUpload. How can I clear the file and change the background color of the fileupload

btnAudUpload_Click Method

string filename =FileUpload.FileName;
string Fullpath = Path.Combine(@"D:\Media", filename);
if (FileUpload.HasFile)
  { 
 if (filename.ToLower().EndsWith("mp4"))
     {  
      //Saving the file
     }
  else
     {
          //I want to clear the  FileUpload content here
     }    
  }

Answer

Gaddiel Sadoc Peralta picture Gaddiel Sadoc Peralta · Jan 16, 2013

Clear the Attributes worked for me... but that will remove styles and other stuff

string filename =FileUpload.FileName;
string Fullpath = Path.Combine(@"D:\Media", filename);
if (FileUpload.HasFile)
{ 
  if (filename.ToLower().EndsWith("mp4"))
  {  
     //Saving the file
  }
  else
  {
     //I want to clear the  FileUpload content here
     FileUpload.Attributes.Clear();
  }    
}