.NET

Reply
Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 1 of 26 (395 Views)
Accepted Solution

VB.NET SAVEAS / eFileAccessErr

395 Views, 25 Replies
01-14-2014 11:41 AM

Hi,

whenever I try to save my curret drawing as I will get this error.

I was looking here what could be the issue but no success yet.

Do you now what could be the problem?

Many thanks.

 

I used standard method;

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
 
<CommandMethod("SaveActiveDrawing")> _
Public Sub SaveActiveDrawing()
  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
  Dim strDWGName As String = acDoc.Name
 
  Dim obj As Object = Application.GetSystemVariable("DWGTITLED")
 
  '' Check to see if the drawing has been named
  If System.Convert.ToInt16(obj) = 0 Then
      '' If the drawing is using a default name (Drawing1, Drawing2, etc)
      '' then provide a new name
      strDWGName = "c:\MyDrawing.dwg"
  End If
 
  '' Save the active drawing
  acDoc.Database.SaveAs(strDWGName, True, DwgVersion.Current, _
                        acDoc.Database.SecurityParameters)
End Sub

 

Valued Mentor
gasty1001
Posts: 450
Registered: ‎04-11-2010
Message 2 of 26 (386 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-14-2014 12:23 PM in reply to: xpeter88

Hi,

 

Do you have permision to write in C:\?

 

Gaston Nunez

Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 3 of 26 (383 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-14-2014 12:27 PM in reply to: gasty1001

Sure, I am on my laptop and there is no issue to manipulate with any files :-/

Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 4 of 26 (381 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-14-2014 12:32 PM in reply to: xpeter88

This is that error;

 

Untitled.png

 

Valued Mentor
gasty1001
Posts: 450
Registered: ‎04-11-2010
Message 5 of 26 (360 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-14-2014 01:46 PM in reply to: xpeter88

Hi,

 

Just try the same code, but this time saving to a folder, and see what happens. This may help:Disabling UAC

 

Gaston Nunez

Mentor
mzakiralam
Posts: 230
Registered: ‎11-09-2012
Message 6 of 26 (340 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-15-2014 02:58 AM in reply to: xpeter88

Hi,
sometimes if you do not lock the document then this type of error occurs. As you are using command method so document should be locked automatically. But you can try to lock the document in code explicitly and try the code once again.

Contributor
jon-p
Posts: 18
Registered: ‎01-04-2013
Message 7 of 26 (329 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-15-2014 06:52 AM in reply to: xpeter88

Peter,

Yes, it happens.  We fought with the SaveAs api in Autocad for a LONG time.  The following is what we have thus far.  It's a shame that something so basic / trivial has to be such a pain.

 

	''' <summary>
	''' saves the current drawing
	''' </summary>
	''' <param name="db">the database / drawing</param>
	''' <remarks>We only had to write this because the autocad api is retarded</remarks>
	<Extension()>
	Public Sub SaveDamnYou(db As Database)
		Dim doc As Document = Nothing
 
		Try
			doc = DocumentManager.GetDocument(db)
		Catch
			'db is in batch mode
		End Try
 
		'If we have a document, attempt to call a quick save
		If doc IsNot Nothing Then
			If doc.IsReadOnly Then
				Throw New ROCException("Save failed. Drawing is Read-Only.")
			Else
 
				Try
					doc.Save()
				Catch ex As Exception
					doDBSave(db)
				End Try
 
 
			End If
		Else
		'If no document, attempt to save the database itself
		doDBSave(db)
		End If
 
	End Sub
 
	''' <summary>
	''' Attempts to save the database to itself, or logs an error if it fails
	''' </summary>
	''' <param name="db"></param>
	''' <remarks></remarks>
	Public Sub doDBSave(db As Database)
		Try
			Dim DwgFilePath As String = db.GetRealFilename
			db.SaveAs(DwgFilePath, TrueDwgVersion.Current, db.SecurityParameters)
		Catch ex As Autodesk.AutoCAD.Runtime.Exception
 
			LogInfo("Acad Error Status: {0}".FMe(ex.ErrorStatus))
			Throw
		End Try
	End Sub
 
	''' <summary>
	''' Saves the document via COM
	''' </summary>
	''' <param name="doc">document to be saved </param>
	''' <remarks>Used by the above save routine to allow a lock document to be saved, because the API is SUPER retarded</remarks>
	<Extension()>
	Public Sub Save(doc As Document)
 
		Dim adoc As Interop.AcadDocument = CType(doc.AcadDocument, Interop.AcadDocument)
		'adoc.Save()
		adoc.SendCommand("_QSAVE ")
 
	End Sub
 
	''' <summary>
	''' gets the real filename of the database. instead of .sv$ filenames
	''' </summary>
	''' <param name="db">the database / drawing</param>
	''' <returns>returns the real filename</returns>
	''' <remarks>http://through-the-interface.typepad.com/through_the_interface/2008/03/getting-the-ful.html</remarks>
	<Extension()>
	Public Function GetRealFilename(db As DatabaseAs String
		Dim doc As Document = Nothing
		Try
			doc = DocumentManager.GetDocument(db)
		Catch
			'This error indicates that there is no document object
		End Try
		'is this open in batch mode?
		If doc Is Nothing Then
			Return db.Filename
		Else
			Return doc.Name
		End If
	End Function
Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 8 of 26 (301 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-16-2014 08:03 AM in reply to: gasty1001

gasty1001 wrote:

Hi,

 

Just try the same code, but this time saving to a folder, and see what happens. This may help:Disabling UAC

 

Gaston Nunez


No this did not help.

Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 9 of 26 (301 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-16-2014 08:04 AM in reply to: mzakiralam

mzakiralam wrote:

Hi,
sometimes if you do not lock the document then this type of error occurs. As you are using command method so document should be locked automatically. But you can try to lock the document in code explicitly and try the code once again.


No success as well :/ I tried to lock the document already.

Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 10 of 26 (298 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-16-2014 08:08 AM in reply to: jon-p

jon-p: What references do I have to use? Some expressions are not recognized. I've got loaded AcCui, AcDbMgd, AcMgd.

 

Then;

Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Colors

 

Nothing else I do not need for code I have. But it seems that for your code I missed something. 

 

 

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community