Thread: file upload
View Single Post
Join Date: Dec 2008
Posts: 37
Reputation: kischi is an unknown quantity at this point 
Solved Threads: 0
kischi kischi is offline Offline
Light Poster

file upload

 
0
  #1
Dec 28th, 2008
Hi I am trying to upload an excel file to the server.
But it won't work, every time I am trying to upload an xls file and press the button. it writes: No file was uploaded.

as if i had no file. you are welcome to try on: http://radio.web.surftown.dk/admin/indset_program.aspx
the top section where you can upload a file from your computer

my code looks like this:

  1. protected void Button2_Click(object sender, EventArgs e)
  2. {
  3. string sSavePath;
  4.  
  5. sSavePath = "../";
  6.  
  7. if (FileUpload.PostedFile != null)
  8. {
  9. // Check file size (mustn’t be 0)
  10. HttpPostedFile myFile = FileUpload.PostedFile;
  11. int nFileLen = myFile.ContentLength;
  12. if (nFileLen == 0)
  13. {
  14. lblOutput_excel.Text = "No file was uploaded.";
  15. return;
  16. }
  17.  
  18.  
  19. if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".xls")
  20. {
  21. lblOutput.Text = "The file must have an extension of xls";
  22. return;
  23.  
  24. }
  25.  
  26. byte[] myData = new Byte[nFileLen];
  27. myFile.InputStream.Read(myData, 0, nFileLen);
  28.  
  29. System.IO.FileStream newFile
  30. = new System.IO.FileStream(Server.MapPath(sSavePath),
  31. System.IO.FileMode.Create);
  32. newFile.Write(myData, 0, myData.Length);
  33. newFile.Close();
  34.  
  35. }
  36.  
  37.  
  38.  
  39. }
Hope someone can help?
Last edited by peter_budo; Dec 29th, 2008 at 11:32 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote