Click here to Skip to main content
15,881,781 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Want to open existing workbook from folder using c#.net web application.
Posted
Comments
So, what is the issue?
Member 11838322 24-Sep-15 13:04pm    
here my code:
string extn = Path.GetExtension(FileUpload18.PostedFile.FileName);
Microsoft.Office.Interop.Excel.Application xlApp;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
string constr = Server.MapPath("~\\Input_MRDB_Cost_Upload\\MRDB_Cost rates_Template.xlsx");
//xlWorkBook = xlApp.Workbooks.Open(constr, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",true, false, 0, true, false, false);
xlWorkBook = xlApp.Workbooks.Open(Filename: @constr, ReadOnly: false);
xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item("MRDB_Cost rates_Template");
Microsoft.Office.Interop.Excel.Range formatRange;
formatRange = xlWorkSheet.get_Range("A3").EntireColumn;
formatRange.NumberFormat = "@";
string constr1 = Server.MapPath("~/Input_MRDB_Cost_Upload/") + Guid.NewGuid() + extn;
xlApp.ActiveWorkbook.SaveAs(constr1, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
xlApp.ActiveWorkbook.Saved = true;
// xlWorkBook.SaveAs(constr, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, null, null, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null);
xlWorkBook.Close();
xlApp.Quit();

Sorry, we couldn't find C:\Users\goutam.x.pal\Desktop\NEWDFM\Input_MRDB_Cost_Upload\MRDB_Cost rates_Template.xlsx. Is it possible it was moved, renamed or deleted?

1 solution

Hi,

you can use process to open any file.

System.Diagnostics.Process.Start(@"file path");


Thanks,
Sisir Patro
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900