PDA

View Full Version : Problem writing to a file



ppirtle
2008-02-15, 07:14 PM
Once again, I'm learning Visual Studio 2008 at the same time as I'm playing with the Revit API. I'm following the labs from AU2007, but seem to be struggling. What I'm trying to do today is simply to write to a text file. Here's my code:

'I've imported System and System.IO
Try
Dim fileName As StreamWriter = New StreamWriter("C:\temp\test2.txt")
Catch ex As Exception
MsgBox("Can't open file: " & ex.Message)
End Try

I get the message box as follows:

"Can't open file. Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

When I try this outside of Revit in a Windows Forms app, it works just fine.

TIA for any help and suggestions.

GuyR
2008-02-15, 08:23 PM
Hello ppirtle,

The joys of security and .NET... Either you're trying to access a file on the network or the command is being run from a network path. Depending on which it is will determine what the solution is.

oops, just noticed it's not a network path for the file. What is the location of the command dll?

HTH,

Guy

ppirtle
2008-02-15, 09:20 PM
The joys of security and .NET... Either you're trying to access a file on the network or the command is being run from a network path.


Yup. Yup. I was compiling my DLL to a network drive. Moving it over to my C: drive works fine.

I'm learning a BUNCH. Hope I don't wear out my welcome asking questions before I know enough to help someone else. Thanks a bunch!

GuyR
2008-02-15, 09:23 PM
You can make it run from the network drive, it just needs to be full trust.

Guy