Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

.NET Forum


You are currently viewing our .NET Forum as a guest. Please register to participate.
Login



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

Posts: 26
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
 
 
Register now for full access!
Old 12-28-2008, 12:32 PM Re: file upload
Banned

Posts: 421
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;
}
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?
__________________

Please login or register to view this content. Registration is FREE
specialk is offline
Reply With Quote
View Public Profile
 
Old 12-29-2008, 02:36 AM Re: file upload
Average Talker

Posts: 26
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: 26
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.34467 seconds with 12 queries