Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Mon Mar 18, 2013 10:26 pm

Hi !

I get an exception error " ERROR: Could not find a part of the path 'C:\Program Files\Common Files\Microsoft Shared\DevServer\test\Book3.xls'."

The code used is-
try
{

FileUpload1.SaveAs(Server.MapPath("/test/" + FileUpload1.FileName));
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
//initialize a new Workbook object
Workbook workbook = new Workbook();
//open an excel file
workbook.LoadFromFile(@"..\test\Book3.xls");
//get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//delete the twelfth row of the first sheet
sheet.DeleteRow(1);
//delete the second column of the first sheet
// sheet.DeleteColumn(2);
//save the excel file
workbook.SaveToFile("Book3.xls", ExcelVersion.Version2007);
//launch the excel file
System.Diagnostics.Process.Start(workbook.FileName);


}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}

I even tired Server.MapPath but got the same error.
Excel sheet is attached
Please let me know how can i solve this problem.
Attachments
Book3.zip
Excel Sheet
(3.72 KiB) Downloaded 333 times

nathabhishek
 
Posts: 2
Joined: Mon Mar 18, 2013 9:19 pm

Tue Mar 19, 2013 3:10 am

Dear nathabhishek,

Thanks for your inquiry.
We find that file extension of the saved file is not correct in your code. Please refer to the code snippet below to solve this issue.
Code: Select all
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(Server.MapPath("Book3.xls"));
            workbook.Version = ExcelVersion.Version2007;
            Worksheet sheet = workbook.Worksheets[0];

            sheet.DeleteRow(1);

            workbook.SaveToHttpResponse("sample.xlsx", Response, HttpContentType.Excel2007);

If you still have this issue, please tell us.

Have a nice day!

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Thu Mar 21, 2013 10:15 am

Dear nathabhishek,

Does our previous code solve your problem?
Please give you a feedback on this issue at your early convenience.
Thank you!
If you have other any problem, please tell us.

Best regards,
Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar

harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Tue Mar 26, 2013 5:47 pm

Hi !
The problem is solved ! Thanks to Amy and Hary..!

nathabhishek
 
Posts: 2
Joined: Mon Mar 18, 2013 9:19 pm

Wed Mar 27, 2013 1:42 am

Dear nathabhishek,

Thanks for your feedback.
We are happy to hear that.
If you have any issues, please feel free to contact us.
Have a nice day!

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.XLS