| | |
file upload
Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 37
Reputation:
Solved Threads: 0
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:
Hope someone can help?
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:
asp.net Syntax (Toggle Plain Text)
protected void Button2_Click(object sender, EventArgs e) { string sSavePath; sSavePath = "../"; if (FileUpload.PostedFile != null) { // Check file size (mustn’t be 0) HttpPostedFile myFile = FileUpload.PostedFile; int nFileLen = myFile.ContentLength; if (nFileLen == 0) { lblOutput_excel.Text = "No file was uploaded."; return; } if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".xls") { lblOutput.Text = "The file must have an extension of xls"; return; } byte[] myData = new Byte[nFileLen]; myFile.InputStream.Read(myData, 0, nFileLen); System.IO.FileStream newFile = new System.IO.FileStream(Server.MapPath(sSavePath), System.IO.FileMode.Create); newFile.Write(myData, 0, myData.Length); newFile.Close(); } }
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.
•
•
Join Date: Jul 2008
Posts: 49
Reputation:
Solved Threads: 7
Okay, i just saw a reference to Update Panel in your page code, but your upload control is declared outside of it. Use breakpoints and run your page in debug mode. Set break points inside of the first if statement and see what you're getting in FileUpload.PostedFile. Check for any internal errors and property values.
Also, don't use system.io to save the file. You can do so with FileUpload.PostedFile.SaveAs();
Also, don't use system.io to save the file. You can do so with FileUpload.PostedFile.SaveAs();
Last edited by iDeveloper; Dec 28th, 2008 at 8:41 pm.
•
•
Join Date: Dec 2008
Posts: 37
Reputation:
Solved Threads: 0
Ok I put some breakpoints at:
if (FileUpload.PostedFile != null)
and
int nFileLen = myFile.ContentLength;
And when i move the curser over:
int nFileLen = myFile.ContentLength;
it writes: myFile.ContentLength 0
does that meen that it thinks that the file doesn't fill more than 0?
and how do I change that?
if (FileUpload.PostedFile != null)
and
int nFileLen = myFile.ContentLength;
And when i move the curser over:
int nFileLen = myFile.ContentLength;
it writes: myFile.ContentLength 0
does that meen that it thinks that the file doesn't fill more than 0?
and how do I change that?
•
•
Join Date: Jul 2008
Posts: 49
Reputation:
Solved Threads: 7
•
•
•
•
Ok I put some breakpoints at:
if (FileUpload.PostedFile != null)
and
int nFileLen = myFile.ContentLength;
And when i move the curser over:
int nFileLen = myFile.ContentLength;
it writes: myFile.ContentLength 0
does that meen that it thinks that the file doesn't fill more than 0?
and how do I change that?
Last edited by iDeveloper; Dec 29th, 2008 at 10:04 pm.
•
•
Join Date: Dec 2008
Posts: 3
Reputation:
Solved Threads: 1
//use System.Web.UI.HtmlControls.HtmlInputFile >> filSelectFile
string nameOfFile = filSelectFile.Value;//Get selected file
//Get actual file name
int last = nameOfFile.LastIndexOf("\\");
nameOfFile = nameOfFile.Substring(last + 1);
//Saving location
//this must be virtual folder of your web server
string uploadFolder = ConfigurationSettings.AppSettings["FileUploadFolder"];
nameOfFile = uploadFolder +"\\" + nameOfFile;
//Upload the file
filSelectFile.PostedFile.SaveAs(nameOfFile);
string nameOfFile = filSelectFile.Value;//Get selected file
//Get actual file name
int last = nameOfFile.LastIndexOf("\\");
nameOfFile = nameOfFile.Substring(last + 1);
//Saving location
//this must be virtual folder of your web server
string uploadFolder = ConfigurationSettings.AppSettings["FileUploadFolder"];
nameOfFile = uploadFolder +"\\" + nameOfFile;
//Upload the file
filSelectFile.PostedFile.SaveAs(nameOfFile);
Last edited by ruwanthaka; Dec 29th, 2008 at 11:47 pm.
•
•
Join Date: Dec 2008
Posts: 37
Reputation:
Solved Threads: 0
The autentication was allready set to Windows.
Where would I put this into the code. Or is this the only code that should be on the page instead of my other code?
Thanks
•
•
•
•
//use System.Web.UI.HtmlControls.HtmlInputFile >> filSelectFile
string nameOfFile = filSelectFile.Value;//Get selected file
//Get actual file name
int last = nameOfFile.LastIndexOf("\\");
nameOfFile = nameOfFile.Substring(last + 1);
//Saving location
//this must be virtual folder of your web server
string uploadFolder = ConfigurationSettings.AppSettings["FileUploadFolder"];
nameOfFile = uploadFolder +"\\" + nameOfFile;
//Upload the file
filSelectFile.PostedFile.SaveAs(nameOfFile);
Thanks
Last edited by kischi; Dec 30th, 2008 at 3:50 pm.
![]() |
Similar Threads
- File Upload Help (PHP)
- File upload problem (PHP)
- Need file upload code for word Doc (HTML and CSS)
Other Threads in the ASP.NET Forum
- Previous Thread: Can we use view Instead of Query
- Next Thread: Image Comparison Application using ASP.net?..Result in Percentage Format?..!!
| Thread Tools | Search this Thread |
.net 2.0 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox child click commonfunctions compatible confirmationcodegeneration content contenttype courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dropdownmenu edit expose flash flv form formatdecimal forms formview gridview homeedition hosting iframe iis javascript jquery listbox login menu microsoft mono mouse mssql multistepregistration news numerical objects order panelmasterpagebuttoncontrols parent radio ratings reportemail rotatepage save schoolproject search security serializesmo.table silverlight smartcard software sql-server sqlserver2005 suse textbox tracking typeof unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webprogramming webservice xml youareanotmemberofthedebuggerusers





