Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
if (FileUpload1.HasFile)
       {
           byte[] img = new byte[FileUpload1.PostedFile.ContentLength];
          FileUpload1.PostedFile.InputStream.Read(img, 0, FileUpload1.PostedFile.ContentLength);

           string file_ext = FileUpload1.PostedFile.FileName;
           string ext = Path.GetExtension(file_ext);

           Response.Write(FileUpload1.PostedFile.ContentLength);
          
           if ((ext.ToLower() == ".doc") || (ext.ToLower() == ".docx"))
           {
               File.WriteAllBytes(Server.MapPath("~/hello" + ext), img);
           }
          
       }


When Uploading Image its working fine
Posted
Comments
Afzaal Ahmad Zeeshan 29-Mar-15 10:41am    
What error does it give? I believe you shouldn't add a condition here.
Gurpreet Arora Malhotra 29-Mar-15 10:55am    
no error
if ((ext.ToLower() == ".jpg") || (ext.ToLower() == ".jpeg"))
{
File.WriteAllBytes(Server.MapPath("~/hello" + ext), img);
}
Image Uploaded

when I try Docx . It doesnot show any error doesnot upload file

I think file upload.save method or something needs to be used instead of file.writeallbytes
 
Share this answer
 
File that i want to upload its Empty thats why unable to load
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-May-15 2:18am    
What is the abuse! Not only you posted non-answer as "solution", you even accepted it as "solution". Please remove it, to avoid abuse reports.
—SA

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