tags:

views:

273

answers:

2

Hi I have a serious issue. I am using excel object for opening the excel file it works fine i my PC. when i make application as a website and running the page and uploading it gives the error "'C:\Documents and Settings\Administrator\Desktop\Work\SABRE MSO Mapping Request Template.xlsx' could not be found. Check the spelling of the file name, and verify that the file location is correct. If you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or deleted. ".

I think it taking server path...but i want to open client excel file before saving the file to the server.

Plz help.

A: 

have you tried server.mappath() method ?? Do you have proper permissions setup to access the folder??

Perpetualcoder
I want to open client Machine excel file to read and check certain things and then save that file to server.
Xyz
see this very detailed article, concentrate on the excel bit.
Perpetualcoder
http://aspnet.4guysfromrolla.com/articles/030508-1.aspx
Perpetualcoder
A: 

Are you passing complete file path to the excel for opening the file? Please try this:

    if (fileUpload.HasFile)
    {
        string fileName = "PATH_RELATIVE_TO_YOUR_SITE" + "FILE_NAME";
        fileUpload.PostedFile.SaveAs(fileName);
        //NOW open excel using fileName;
    }

also you need write permissions to the path (folder) you are writing file to.

TheVillageIdiot
want to open client Machine excel file to read and check certain things and then save that file to server.
Xyz
I am using this code objWorkBook = objExcel.Workbooks.Open(inputFileUpload1.PostedFile.FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Xyz
Opsss! the inputFileUpload1.PostedFile.FileName gives you only the name of the file like *mytestFile.xls* and when you pass this to excel object it think its resolving it relative to your home directory (the directory in which your web app is running) it the file you want to open is in your site directory please use *Server.MapPath("/" + fileName)* to get correct path.
TheVillageIdiot