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.
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.
FileUploader control does not work in the upload panel. In other words, it isn't Ajax compatible control. You need to do a regular postback through a trigger. It's a security constraint in the design of the component. You can look it up on msdn.
Last edited by iDeveloper; Dec 28th, 2008 at 4:07 pm.
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();
Last edited by iDeveloper; Dec 28th, 2008 at 8:41 pm.
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?
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?
Open your web.config. Look at the <authentication> tag and check the mode. Is it set to "Forms"? If so, change it to "Windows". This *should* work. Note, however, that anybody running that page will run as aspnet user. You can use impersonation to impersonate an account with less privileges. Now, don't judge me on this but this probably makes sense since you're uploading data to the server, i'd imagine you have to be able to do this as a privileged user, hence the windows authentication mode. Hope that helps.
Last edited by iDeveloper; Dec 29th, 2008 at 10:04 pm.
//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);
Last edited by ruwanthaka; Dec 29th, 2008 at 11:47 pm.
//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);
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?
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.