ReadDwgFile - eFileSharingViolation

ReadDwgFile - eFileSharingViolation

Anonymous
Not applicable
4,372 Views
5 Replies
Message 1 of 6

ReadDwgFile - eFileSharingViolation

Anonymous
Not applicable
Hi,

A Question: I'm getting a eFileSharingViolation when I use the method "ReadDwgFile" if the selected drawing is open.

Is it not possible to use a open drawing with this method?
If so, any idea on a workaround for this?


using (DocumentLock docLock = Application.DocumentManager.MdiActiveDocument.LockDocument())
{
using (Database db = new Database(false, false))
{
db.ReadDwgFile(fname, System.IO.FileShare.Read, true, null);
using (Transaction t = doc.TransactionManager.StartTransaction())
{
ObjectId idBTR = doc.Database.Insert(BlockName, db, false);
t.Commit();
}

}
}


A Caddie
0 Likes
4,373 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
ps. using: AutoCAD 2008, VS2005, WinXP pro sp2
0 Likes
Message 3 of 6

Anonymous
Not applicable
It looks like you are locking the active document, then opening a database, then doing a transaction in another unknown document (doc).
Something was bound to break.
You should be locking the same document you are having the transaction with.
0 Likes
Message 4 of 6

Anonymous
Not applicable
Hi Mark,

I'll have to clean up my code.
Before I start the transaction I set "doc" also to the active MdiDocument....so the Lock and transactions are the same document...

Well i corrected the code, but still same trouble.
I can insert drawing that aren't open, and the message "eFileSharingViolation" sounds to me like it wants to lock the file, but because the file is open it can't lock it....

here's the error I get:
Error Autodesk.AutoCAD.Runtime.Exception: eFileSharingViolation
at Autodesk.AutoCAD.DatabaseServices.Database.ReadDwgFile(String fileName,
FileShare fileSharing, Boolean allowCPConversion, String password)

O, I just checked the ObjectARX documentation on this method again......seems it can't access files already open.

Just tried to insert a file set to Read-Only...this goes!!!??

Seems You can't use this on a open file 😞

Maybe copy the file first to a temp location...and read it there
Anyone another solution

A Caddie.
0 Likes
Message 5 of 6

Anonymous
Not applicable
Hi All,

Well seems after reading the ObjectARX several times on "ReadDwgFile" that the mode specified determines what other processes can do to the file, well because it's a open file it needs Write (or read) access.. so "System.IO.FileShare.ReadWrite" instead of "Read" solves the problem...the documentation only gives a warning that the file could change during the "ReadDwgFile" method.

But because I want to insert the whole drawing (as block) into the current drawing that shouldn't be a issue, maybe only with a large drawing...

A. Caddie
Message 6 of 6

Anonymous
Not applicable
Document 'locking' has nothing to do with file locking
or share permissions. When one application locks the
document, that tells AutoCAD that it shouldn't allow
any other application to modify the state or data of
that document or its database (here, 'document' and
'database' refer to the in-memory objects, not the
source DWG file).

In general, the ObjectARX docs clearly explain many
things that eliminate the need for speculation.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5731489@discussion.autodesk.com...
It looks like you are locking the active document, then opening a database, then doing a transaction in another unknown document (doc).
Something was bound to break.
You should be locking the same document you are having the transaction with.
0 Likes