Reply
Old 12-28-2008, 11:41 AM file upload
Average Talker

Posts: 24
Name: Adam Kischinovsky
Trades: 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:

Code:
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();
        
        }

                    

    }
Hope someone can help?
Kischi is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 12-28-2008, 12:32 PM Re: file upload
webcosmo's Avatar
Ultra Talker

Posts: 255
Location: Boston, MA
Trades: 1
That means somehow your selected file is not been detected. Make sure that part works.

if (nFileLen == 0)
{
lblOutput_excel.Text = "No file was uploaded.";
return;
}
__________________
JOIN US * FAST GROWING WEBMASTER FORUM * JOIN US
Join the fun loving, helpful community of webmasters
Free Classified Ads
webcosmo is offline
Reply With Quote
View Public Profile Visit webcosmo's homepage!
 
Old 12-28-2008, 01:17 PM Re: file upload
Super Talker

Posts: 143
Trades: 0
Do you get the same error message with other types of files or is this problem only when you try to upload and xls file? I wonder if this file type is not supported for some reason?
__________________
www.yurx.com
specialk is offline
Reply With Quote
View Public Profile
 
Old 12-29-2008, 02:36 AM Re: file upload
Average Talker

Posts: 24
Name: Adam Kischinovsky
Trades: 0
I just tried to upload a jpg file and it says exactly the same: No file was uploaded.
?
Kischi is offline
Reply With Quote
View Public Profile
 
Old 12-30-2008, 04:09 PM Re: file upload
Average Talker

Posts: 24
Name: Adam Kischinovsky
Trades: 0
I got it to work now.
I just had to write:
sSavePath = "../test.xls";

instead of: sSavePath = "../
Kischi is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to file upload
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.12223 seconds with 13 queries