|
-
Jul 3rd, 2002, 06:30 AM
#1
Thread Starter
New Member
Writing to a text file
I am trying to write to a text file using VB.NET, I have used the code as explained in a book called "Professional VB.NET" and also on a website. However I still get Permission errors.
The part of my code that deals with granting the permissions, opening the file for append and then adding to the file is shown below:
Dim FilePermission As FileIOPermission = New FileIOPermission(FileIOPermissionAccess.AllAccess,
"C:\Inetpub\wwwroot\temp\pickfile2.lst")
FilePermission.Assert()
Try
Dim writer1 As New StreamWriter(File.Open("C:\Inetpub\wwwroot\temp\pickfile2.lst",
FileMode.Append))
writer1.WriteLine(Store.BoxID(Store.BoxNo) & "," & Store.OldLoc(Store.BoxNo)
& "," & Store.NewLoc(Store.BoxNo))
writer1.Close()
Catch objA As System.Exception
MessageBox.Show(objA.Message)
End Try
However when I run this code I get the following error:
Request for the permission of type System.Security.Permissions.FileIOPermission,
mscorlib, Version=1.0.3300.0, Culture=netural, PublicKeyToken=b77a5c561934e089
failed.
__________________
David Bradley
[email protected]
-
Jul 3rd, 2002, 06:38 AM
#2
Registered User
VB Code:
Dim MDocument As New System.IO.FileStream("Sample.txt", IO.FileMode.Create, IO.FileAccess.Write)
Dim w As New System.IO.StreamWriter(MDocument)
w.BaseStream.Seek(0, IO.SeekOrigin.End)
w.WriteLine("Sample Text")
w.WriteLine("Sample Text")
w.Flush()
w.Close()
This will work...
Jeff
-
Jul 3rd, 2002, 07:35 AM
#3
Thread Starter
New Member
Cheers Jeff for that suggestion.
However, after inserting your suggested code without
Dim FilePermission As FileIOPermission = New FileIOPermission(FileIOPermissionAccess.AllAccess, "C:\Inetpub\wwwroot\1sStorage_VBNET\PickApp\bin\pickfile3.lst")
FilePermission.Assert()
in the code I get the following error:
An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll
Additional information: Request for the permission of type System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
With the FilePermission etc in I get the same error as before:
Request for the permission of type System.Security.Permissions.FileIOPermission,
mscorlib, Version=1.0.3300.0, Culture=netural, PublicKeyToken=b77a5c561934e089
failed.
This is how my code looks now after your suggestion:
Dim outFile As New System.IO.FileStream("C:\Inetpub\wwwroot\1sStorage_VBNET\PickApp\bin\pickfile3.lst", IO.FileMode.Create, IO.FileAccess.Write)
Dim writer1 As New System.IO.StreamWriter(outFile)
writer1.BaseStream.Seek(0, IO.SeekOrigin.End)
writer1.WriteLine(Store.BoxID(Store.BoxNo) & "," & Store.OldLoc(Store.BoxNo) & "," & Store.NewLoc(Store.BoxNo))
writer1.Flush()
writer1.Close()
Cheers
David
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|