Solved

File Path Error

Posted on 2010-09-01
10
1,375 Views
Last Modified: 2012-05-10
Error Paths

I have an application that saves the excel files to a location on another server.  users will be accessing this application, so I decided to use UNC paths.  However, I am getting an error.

UNC Path:
string strFile = @"\MY SERVER\Inetpub\wwwroot\BALAReporting\Invalid DataInetpub\wwwroot\BALAReporting\Invalid Data\InvalidData_" + postdate + ".xls";

Open in new window


Error exporting data to spreadsheet

System.Runtime.InteropServices.COMException (0x800A03EC): 'C:\hqspsdev01\Inetpub\wwwroot\BALAReporting\Invalid DataInetpub\wwwroot\BALAReporting\Invalid Data\InvalidData_090110_050502PM.xls' cannot be accessed. The file may be corrupted, located on a server that is not responding, or read-only. at Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local) at DelinquentReport.exportToExcel(DataTable dt, String fileloc) in c:\Inetpub\wwwroot\DelinquentRep\Default.aspx.cs:line 291 at DelinquentReport.btnInvalidData_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\DelinquentRep\Default.aspx.cs:line 356


with the path changed to:

string strFile = @"\\MY SERVER\Inetpub\wwwroot\BALAReporting\Invalid DataInetpub\wwwroot\BALAReporting\Invalid Data\InvalidData_" + postdate + ".xls";

Open in new window


I get the following error:

Error exporting data to spreadsheet

System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC at Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local) at DelinquentReport.exportToExcel(DataTable dt, String fileloc) in c:\Inetpub\wwwroot\DelinquentRep\Default.aspx.cs:line 291 at DelinquentReport.btnInvalidData_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\DelinquentRep\Default.aspx.cs:line 356

what can i do to prevent the error?



0
Comment
Question by:ayoZen
  • 5
  • 4
10 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 250 total points
ID: 33581662
has it got something to do with the read access?
e.g. is it open for read only instead of read/write / create?
0
 
LVL 7

Assisted Solution

by:jdavistx
jdavistx earned 250 total points
ID: 33581711
Is your path copied from your code, or did you type it? It appears to be missing a backslash before "Inetpub"

You also appear to have this in there twice:
"Inetpub\wwwroot\BALAReporting\Invalid Data"
0
 
LVL 7

Expert Comment

by:jdavistx
ID: 33581715
Try this as your string?
string strFile = @"\\MY SERVER\Inetpub\wwwroot\BALAReporting\Invalid Data\InvalidData_" + postdate + ".xls";

Open in new window

0
 

Author Comment

by:ayoZen
ID: 33588376
i updated my file and still get the following error:

Error exporting data to spreadsheet to
THIS IS THE PATH
\\MY SERVER NAME HERE\Inetpub\wwwroot\BALAReporting\Invalid Data\InvalidData_090210_120902PM.xls

System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC at Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local) at DelinquentReport.exportToExcel(DataTable dt, String fileloc) in c:\Inetpub\wwwroot\DelinquentRep\Default.aspx.cs:line 291 at DelinquentReport.btnInvalidData_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\DelinquentRep\Default.aspx.cs:line 359
0
 

Author Comment

by:ayoZen
ID: 33588385
I set the avriable to :

[code]
string strFile = @"\\MY SERVER\Inetpub\wwwroot\BALAReporting\Invalid Data\InvalidData_" + postdate + ".xls";
[/code]
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:ayoZen
ID: 33588694
I tried to modify the folder permissions too?  Is the error indicating that the problem is the path or the folder?
0
 
LVL 7

Expert Comment

by:jdavistx
ID: 33589874
Not sure, are you able to simply write a new file to that folder via Windows explorer? If so, then it's not a persmission issue.
0
 

Author Comment

by:ayoZen
ID: 33591425
yes.  i can save files to that folder without a problem.  
0
 
LVL 7

Expert Comment

by:jdavistx
ID: 33599439
Can you write this file locally?
0
 

Author Comment

by:ayoZen
ID: 33662463
Thank you jdavistx and TheRealLoki for your help!  After careful reveiw, I created a folder on the same server without a problem.  I changed the saveas option in my excelExport method:

[code]
owb.SaveAs(fileloc, Excel.XlFileFormat.xlWorkbookNormal, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
[/code]

finally,  my file names became:

[code]
           string postdate = Convert.ToString(DateTime.Now.ToString("MMddyy_hhmmsstt"));
           string dirName = @"C:\BALA Delinquent App\Delinquent Reports\";
           string strFile = "delinquentReport_" + postdate + ".xls";
            DirectoryInfo dInfo = new DirectoryInfo(dirName);
....rest of code
 exportToExcel(gt, dInfo + strFile);
[/code]

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now