Results 1 to 4 of 4

Thread: Problem writing to a file

  1. #1
    100 Club
    Join Date
    2006-07
    Posts
    130
    Login to Give a bone
    0

    Default Problem writing to a file

    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.

  2. #2
    AUGI Addict
    Join Date
    2003-11
    Location
    New Zealand
    Posts
    1,116
    Login to Give a bone
    0

    Default Re: Problem writing to a file

    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
    Last edited by GuyR; 2008-02-15 at 08:53 PM.

  3. #3
    100 Club
    Join Date
    2006-07
    Posts
    130
    Login to Give a bone
    0

    Default Re: Problem writing to a file

    Quote Originally Posted by GuyR View Post
    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!

  4. #4
    AUGI Addict
    Join Date
    2003-11
    Location
    New Zealand
    Posts
    1,116
    Login to Give a bone
    0

    Default Re: Problem writing to a file

    You can make it run from the network drive, it just needs to be full trust.

    Guy

Similar Threads

  1. Writing dwg's to a zip file.
    By kdayman in forum VBA/COM Interop
    Replies: 14
    Last Post: 2008-08-12, 06:13 PM
  2. Writing a DXF file
    By meyekj in forum AutoLISP
    Replies: 5
    Last Post: 2008-06-13, 05:34 AM
  3. STC failure with error writing to backup file
    By Wes Macaulay in forum Revit - Worksharing/Worksets/Revit Server
    Replies: 6
    Last Post: 2007-10-03, 12:40 AM
  4. Writing to a text file
    By ewuensch in forum AutoLISP
    Replies: 4
    Last Post: 2007-02-22, 01:05 PM
  5. Replies: 1
    Last Post: 2005-08-13, 04:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •