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.";

            if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".xls")
                lblOutput.Text = "The file must have an extension of xls";


            byte[] myData = new Byte[nFileLen];
            myFile.InputStream.Read(myData, 0, nFileLen);

            System.IO.FileStream newFile
                        = new System.IO.FileStream(Server.MapPath(sSavePath),
            newFile.Write(myData, 0, myData.Length);



Hope someone can help?

This article has been dead for over six months. Start a new discussion instead.