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:

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?

Recommended Answers

All 2 Replies

Ok sorry, now I have copied it to asp.net

I'm sorry for the mistake,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.