.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Error opening an excel file

Posted By:      Posted Date: September 24, 2010    Points: 0   Category :Windows Application
I'm getting this error while trying to open an excel file from my application. I tried this http://blog.crowe.co.nz/archive/2006/03/02/589.aspx but it didn't help. Excel itself opens normally, but it does not from my application. here is a screenshot of my code:
        case "xls":
          System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("ru-RU");
          Microsoft.Office.Interop.Excel.WorkbookClass wb = new Microsoft.Office.Interop.Excel.WorkbookClass();
          wb.Application.Visible = true;
          wb.Application.Workbooks.Open(fileName.ToString(), updateLinks, readOnly,
            missing, missing, missing, missing, missing,
            missing, missing, missing, missing, missing,
            missing, missing);
I didn't find a solution in another threads. Please help me... this option is cruicial in my application. Thank you!


View Complete Post

More Related Resource Links

Export to Excel gives error before opening file


I have a web page with a gridview control and a button for Exporting to Excel

I get following error when exporting to Excel.

"The fiel you are trying to open, 'someFileName[1].xls, is in a different format than specified by the file extension. Verify that file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"

Clicking Yes opens the file. I would like to avoid showing the above error to the users.

Following code is used from the click event. I've left the commented code here to show what I've tried based on results from internet search. I have Microsoft Office Excel 2007 on local PC.

public static void ToExcel(DataTable dt, string fileName)
			string attachment = "attachment; filename=" + fileName + ".xls";

			GridView gvExcel = new System.Web.UI.WebControls.GridView();
			gvExcel.AutoGenerateColumns = true;
			gvExcel.DataSource = dt;

			//HttpContext.Current.Response.AddHeader("content-disposition", attachment);
			//HttpContext.Current.Response.ContentType = "application/ms-excel";
			HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";

Excel file getting error


when i am trying to save a excel document in library it getting error like "The file cannot be saved because some properties are missing or invalid"

If anyone know the solution for this pls tell me.



WSS2.0 opening pdf documents an error message appears: The document could not be saved. The file may

Hi All,. In a WSS2.0 document library, a user is trying to open pdf files. However, an error message is displayed: 'The document could not be saved. The file may be read only, or another user may have it open. Please save the document with a different name or in a different folder'. No one else has the file open. When the user saves the file using Save As (as it is apparently Read Only) and then saves the file back to the SharePoint site, all previous versions of the file disappear. The user has noted that this has been happening since today, and she had some other network issues that have been resolved. No other users are experiencing this problem.  Not sure if this problem is related to the network problems the user was facing. I've had the user reboot but this has not resolved it. Any ideas?

Need an example of error in OLE DB Source component when source is Excel file.

I want an example of error (not truncation) in individual row or individual cell that can occur in OLE DB Source component when source is Excel file. I'm trying out Error Output of data task component.  I have already tried out Error Output of OLE DB Destination component.

Opening a PowerPoint presentation fails with error "invalid path or file name".

When you go to a Document Library and try to open the presentation, PowerPoint opens, but then you get the error "The path or file name for "file URL" is invalid.  Please check that the path and file name are correct."I installed MOSS/WSS SP2 about 2 weeks ago, this happened once or twice before then, but I now know of about a half-dozen presentations that won't open.There is a way to get the file to open, if you hit the drop-down next to the file and select Send To and Download a Copy, you can save or open it from there.If you try browsing to if from within PowerPoint, it won't open either, and will also not open in Explorer View.  We have replaced the file, saved as a different name, etc. with no luck.Using both IE 7 and IE 8 and both XP Pro and Vista Business workstations.Any ideas out there?Thanks,Rusty

Error when opening Excel document from sharepoint


Hi, I am using Sharepoint 2010 and Excel 2010 x64.

I created a document library where I host a simple excel file for testing. When I click on it , it opens in the web browser just fine.

When I chose to open it with Excel , I get this error : The document could not be opened for editing. A microsoft Sharepoint Foundation compatible application could not be found to edit the document.

I already tried as well to do a check out before opening it and it still doesn't work.

Any ideas ?

PS : same thing happens with Visio 2010.


Error opening excel files stored in SharePoint 3.0 from VS2010 (TFS2010 setup)



First I hope this is the correct forum for te below question, and if not, please excuse and if possible divert me to the correct place.

We have a TFS2010 setup with (what I managed to identify) Sharepoint Services 3.0.
We have 2 users working in the same collection, and also share some of the projects in it with the below problems:

1. User A has Office 2007. She is unable to "edit workbook" on an excel file directly from VS2010, and gets an error of 'Unknown error trying to lock file'. I searched this around and didn't find a solution, but did find a workaround - If she checks out the file directly from the SharePoint site, she is able to edit the file, and in fact is able to later "edit workbook" directly from VS2010 (as long as she once checked it out through SharePoint).

2. User B has Office 2010. When he tries to "edit workbook", he gets an error of 'A problem occurred while connecting to the server. If the problem continues, contact your administrator'. When he goes directly to the SharePoint, he is able to check out the file, open it in Excel 2010, but is not able to check it back in (gets an error that the file cannot be located or so, I don't have the exact error). This means that this user cannot work with the SharePpoint stored files at all, and currently works on local copies on hi

Error opening installation log file. Verify that the specified log file locaion exists and is writab


I am running windows 7 and had to reinstall because of gradual problems till finally it would not start. I am reinstalling my programs, I still use MS Money 2001 and am having problems installing it. I have had to set permissions on severial folders to acess them, but I don't know where this one is that the error message refers to. This error message is from windows installer

Could somone point me in the right direction? Money was running on windows 7 after I up graded from Vista.


Jonathan C

Error opening Office Open XML file when using SD workflow to create item in document library.


I have a Sharepoint document library that is using a word template with xml mapping (Word-Sharepoint).

I have a workflow created in Sharepoint designer that Creates an item in this document library with select data from a form library on the same site. 

It appears to create the entry in the document library correctly, it is showing the copied data from the form library and the correct default data in the columns specific to the document library. The explorer view shows the filename.docx files.

I am able to edit the data using the datasheet view, however it will not open the word document.

The error message reads "The Office Open file <filename> cannot be opened because there are problems with the contents." If I click on the details button it states "No error detail available".

Any ideas?

Using the Client Object Model to read values from Excel file produces 504 error



I use the Client Object Model to retrieve and read values from an Excel file. This is triggered in an Event Receiver on the Document Library where the Excel file lives. I use a simple CAML Query to retrieve the file. This has worked just fine on a dev/test server. 
Now, I just recently deployed this solution to a production/live server and now this code doesn't work anymore. I get an error saying 'The remote server returned an error: (504) Gateway Timeout'. This happnes when I try clientContext.ExecuteQuery();

The difference between the two servers is that on the test server (where it works) the solution is sitting as the root site, so to speak. No host headers or nothing.
On the live server, there are several web applications (SharePoint) on the same port, but with different host headers.

I have tried to trace a little bit and I found that on the test server, the url that is used to create the ClientContext object is 'http://<servername>/<webname>'. The url is comes from the following code: web.Url. I tried changing the url to the DNS name the test server has and that resulted in the same error as on the live server.

Does anyone have any idea what I need to do?

Thanks a billion!

Creating Excel file from C#

I used below coding for create a excel sheet.I got from on web site.
In below coding there is no problem.Its create the excel file.If i run second time,its ask to overwrite the current excel file.If I said "Yes" then it ok ,but If I select cancel button,its generate the Error message.The exception is

Convert excel file into xml


Hai, I have two columns with id,name in the excel sheet.I want to convert into xml file in the below format

<?xml version="1.0" encoding="utf-8"?>

<guide xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Boat id="1"> <name> Copper Kettle </name> </Boat> <Boat id="2"> <name> Copper Penny </name> </Boat> <Boat id="3"> <name> Copperhead </name> </Boat> <Boat id="4"> <name> Coppertone </name> </Boat> <Boat id="5"> <name> Copy Boy </name> </Boat> </guide>

suggest me with sample code in ASP.NET. Thanks


Read Excel file from Web Application (C#)



I have a web app where user uploads a file.

File is saved in server locally and I want to read some data from it.

Currently my development  server has office 2003.

So do I need office 2007 in order to be able to  read an excel from office 2007 ?

What are other requirements  ?

I tried a test, using

Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wrkBook; // = new Microsoft.Office.Interop.Excel.Workbook();

wrkBook = excelApp.Workbooks.Open(@"C:\www\excel_files\b.xls", ....);

But When trying to open the file I get the error:

Exception from HRESULT: 0x800A03EC

So I'm wondering what I'm missing.


While Importing Excel 2007 file to Datatable - headerrow problem


Hi there,


I am trying to simply extract an excel data from an uploaded file an put it into a datatable. In this case the excel file has 3 rows but when I fill the datatable I only see row count of 2.

I tried changing HDR:NO; to HDR:YES and vice versa, but no luck. 

What am I doing wrong? (Note: the excel file cannot have a  headerrow)


string connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pFilePath + ";Extended Properties=\"Excel 12.0;IMEX=1;HDR:NO;\"";
            OleDbConnection conn = new OleDbConnection(connstr);
            DataTable dtTables = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
            string strTablename = dtTables.Rows[0]["TABLE_NAME"].ToString();
            string strSQL = "SELECT * FROM [" + strTablename + "]";

            OleDbCommand cmd = new OleDbCommand(strSQL, conn);

            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            //At this point row count=2 which doesn't make sense




Returning datas from two excel file



I used the below code to return the datas from one excel file. My question is if i suppose need to get the records from morethan one excel file using joins, how it is possible.

   string connString = ConfigurationManager.ConnectionStrings["xls"].ConnectionString;
        // Create the connection object 
        OleDbConnection oledbConn = new OleDbConnection(connString);
         // Open connection
            // Create OleDbCommand object and select data from worksheet Sheet1
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);
            // Create new OleDbDataAdapter 
            OleDbDataAdapter oleda = new OleDbDataAdapter();
            oleda.SelectCommand = cmd;
            // Create a DataSet which will hold the data extracted from the worksheet.
            DataSet ds = new DataSet();
            // Fill the DataSet from the data extracted from the worksheet.
            oleda.Fill(ds, "Employees");




Compiler Error Message : CS0006: Metadata file 'System.EnterpriseServices.dll' could not be found


I get this error when i Debug my web application....


I followed these steps.,

  • Ended the aspnet_wp.exe process in the Windows Task Manager
  • Then deleted the application`s folder in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\
  • Then started Visual Studio 2008 again

I also rebooted my system but no use....

Plz help !

Parser Error Message: Could not load type MasterPage File



Server Error in '/' Application.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'wamsilverlight.Web.Wam'.

Source Error:

Line 1:  <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Wam.master.cs" Inherits="wamsilverlight.Web.Wam" %>
Line 2:  
Line 3:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Source File: /Wam.Master    Line: 1

Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4927


All of the following have been tried over and over again:

1.) Delete all existing .dlls

2.) Delete MasterPage File and recreate it.

3.) Delete MasterPage perform a c

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend