I am getting IOException that the file is being used by another process.
I tried to copy - programmatically - the model file to the temp directory but I got the exception.
using (FileStream fsread = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.Read, array_length))
Opening the FileStream fails.
How can I get access to the file used by Revit itself?
Solved! Go to Solution.
Solved by techXMKH9. Go to Solution.
Try different settings and access rights. Maybe using the native Windows API will give you more options than the .NET environment. Can you copy it in the Windows user interface? If not, then maybe you have to close the file in Revit before it can be copied.
You are using a file stream reader to try and save a revit file? That sounds odd to me. Isn't that usually used to read text from a file?
Why not use the Document object most external commands already have? This works in a macro:
SaveAsOptions options = new SaveAsOptions();
UIDocument uidoc = this.ActiveUIDocument;
Document doc = this.ActiveUIDocument.Document;
doc.SaveAs(@"C:\Temp\Test API Save.rvt", options);
For an external command, you will have to modify the UIDocument and Document lines to:
UIApplication uiapp = commandData.Application;
Document doc = uiapp.ActiveUIDocument.Document;
And you will have to find out how to set the file save options. (I'm assuming you probably want to detach your file from the central file.)
Steve
@jeremytammik I forgot to mention that I was able to copy the file through Windows interface. I will different settings.
I do not want to save the Revit file but copy it to a different location.
I did not use
File.Copy(...., ...)
because it is slow for big files.
FileShare.ReadWrite did the trick.
@jeremytammik Thank you.
using (FileStream fsread = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, array_length))
Can't find what you're looking for? Ask the community or share your knowledge.