Exception with Excel SaveCopyAs() method - visual-studio-2010

I have generated a excel report using excel-addins in vs2010 and it saved to desktop. After that I reopened the same file and changed it's data. When I tried to save back with same file name Exception occurs.
Code:-
Globals.ThisAddIn.Application.ActiveWorkbook.SaveCopyAs(saveFileDialog1.FileName);*
Exception:-
System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Excel cannot access the file 'C:\Documents and Settings\112\Desktop\111.xlsx'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.

Check to see that your file isn't being used by something else.
You are almost certainly hitting a file access exception, probably because the document you are attempting to write is already open in another program.
I'm guessing that program is Microsoft Excel.
Close the document in Excel and re-run your test.

Related

How do I detect where is corrupted in a power point file?

I have a power point file(.pptx) generated by a program that copies xml files and content files in a slide to other slides. It simply extracts xml files and content files from original power point file and then copies xml files, finally compresses the files as a zip file and renames the file to xxxxx.pptx. (The xml files I mentioned here is, of course, about Office Open XML)
When I open this file in Keynote on Mac OS X, it works well. No error happened.
However when I use PowerPoint application on Mac OS X, the app says "PowerPoint found a problem with content in xxxxx.pptx"
I think there are differences between PowerPoint specs and Keynote specs, so I need to apply the generated pptx file to the PowerPoint specs.
But, the error does not say WHERE or WHAT ERROR IS OCCURRED, but says there are some errors in that file.
So I cannot look for where is damaged in the generated file!
How do I detect the errors in the file or validate the format of it?
I do not want to get 'restore tools' but 'error detection tools'.
I simply used Open XML SDK 2.5 Productivity Tool.
In my situation, it said the Content-Type of xml files was different from expected one when I opened the pptx file. Soon, it occurred to me I forgot to change the data in [Content_Types].xml
After I fixed it, the file is opened without problems now!!
This app also shows codes in C# and validate each xml files individually.
Download Link is here ->
https://www.microsoft.com/en-us/download/details.aspx?id=30425

What to do with a corrupted DWG file?

I work in AutoCAD 2002. The main file of the drawing when opening AutoCAD gives out "It wasn't succeeded to open this drawing. It contains the incorrect or damaged data". Tried to apply the command to "restore" did not help. Writes that found 3 errors and that all recovered. And opens an empty document as if ctrl+n pressed. Found .the .bak file. when opening it too writes it "It isn't possible to find the specified file of drawing. Be convinced that the specified file exists". and in the folder with the document there is a text acad file (the log of mistakes)
there it is written: FATAL ERROR: Unhandled Access Violation Reading 0x0a2a Exception at 4ad3f5h
02/14/2007 at 09:14:15.204 Drawing: way to the file
that for a problem and what to do??? can eat any else options?. it is very necessary drawing!
I advise you to take this file and to open it in AutoCAD 2005. And try to restore the file with the standard tools of AutoCAD 2005. File -> Utilities -> Recover. After this click SAVE in the 2000 format. And then open it in the working AutoCAD 2002 version. Should help.
Go to this resource and see the theme about DWG files.
https://social.technet.microsoft.com/Forums/en-US/3f956321-2796-49b2-9bd7-6582ad14dd18/drawing-corruptcannot-opencannot-save?forum=itprovistaapps

Internet Explorer file download Excel file filename

I have a bespoke application that downloads an Excel file from the network
The Excel file has a macro within the Workbook Open event. I have noticed that if I put the following code in the event
MsgBox Application.ThisWorkbook.Name
I can see that when the file "PWABCD.XLS" is opened from Internet Explorer 8, the messagebox shows "PWABCD(1).XLS". When the same operation is done from Internet Explorer 10, the message box shows "PWABCD.XLS".
Where is the setting that says the file download name should have (1) inserted? Or is there some other conflict that is causing the (1) to be inserted into the filename? I have inherited logic that assumes the (1) will be there and removes it - rather than amend the code to check for the existence of the (1), is there a setting the user can amend?
Many thanks
The (1) is automatically added to the filename if another file with the same name exists in the destination directory. There is no way to avoid this other than testing to see if the file already exists and deleting it if it does.

Dynamically changing file lock/access permissions on open file

I have a client application where we try to check files in and out from SharePoint for editing. I am using SharePoint's SOAP interfaces and some FrontPage interfaces to do this. It used to work fine under SharePoint 2007, but with 2010 I can't check out or check in a file if I have the file open for editing. I get a message like "FileXXX is locked for exclusive use by DOMAIN\user" when I examine the returned error message. I also cannot update any of the user defined SharePoint fields for a file/list if the file is open for editing.
My question is this: Is there a way to change the access/lock for an open file to make it non-exclusive temporarily and then restore it?
Note: Some of my data files are opened using windows file handles (flat files) and others are opened using windows structured storage (compound document files).
This may not work for Sharepoint specifically, but the ReOpenFile() API does what you want. I don't know of any other way to do this.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365497(v=vs.85).aspx

Excel .xlsx download - sharing violation error message on Open and Save combination

I've found this question posed a few times, but no definitive answers as yet. Looks like a decent solution would help quite a few people.
So we create an excel file (.xlsx) on the server and download it to the client using content-disposition 'attachment'. The Open Save dialog appears and all works fine if you choose Save, or Open and then Save As... However if you choose Open and then hit the Save... button then Excel hangs for a moment and then presents the message:
Your changes could not be saved to 'Export[5].xlsx' because of a sharing violation. Try saving to a different file.
then:
The file you are trying to open 'F8CAC020.IE5\HM2NBE5C\F8CAC020', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
then:
you finally get the Save As: dialog (assuming you pressed 'Yes').
Code for creating the file is:
Response.Clear()
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AppendHeader("content-disposition", "attachment;filename=Export.xlsx")
Response.AddHeader("Content-Length", New System.IO.FileInfo(NewFile).Length)
Response.TransmitFile(NewFile)
Response.Flush()
If you remove the content-disposition header you get the right sort of behaviour in Excel, but with the wrong name and no guarantee that the Excel document will not instead be shown in the browser (depending on client settings). If you press Open and then Save then you
get a message:
'default.aspx' is read-only. To save a copy, click OK, then give the workbook a new name in the Save As dialog box.
So the question is how to combine the 2 behaviours into a reasonable one:
Get the nice error message directly above, when you try to Open and then Save a downloaded file, but also specify that the document should be downloaded and given a default filename.
Cheers,
James
I believe there is a bug in the IE file download code that does not acknowledge the completed file transfer (download) from the web server, thus leaving a connection to the downloaded (temporary) file open when the save is attempted. That generates the "sharing violation" message. I tried the same code with FireFox and I don't get the same result, which surely leads me to believe this is an IE-specific problem.
Unfortunately, given that I believe this to be a bug in IE, I don't think there is presently a clean resolution to this issue.

Resources