scenario.
1. user places csv file in directory
2. user runs console app
3. console app modifies csv, then loads csv into db
the app runs fine locally, but on the shared drive I get the following exception. The appears to be happening when attempt to overwrite the file. the only people using this are Domain Admins.
below is the code and stack trace
I've never encountered this before. And most of my googling returns asp.net issues. Has anyone dealt with this before?
Jason Meckley
Programmer
Specialty Bakers, Inc.
1. user places csv file in directory
2. user runs console app
3. console app modifies csv, then loads csv into db
the app runs fine locally, but on the shared drive I get the following exception. The appears to be happening when attempt to overwrite the file. the only people using this are Domain Admins.
below is the code and stack trace
Code:
private void RemoveHeaders()
{
string[] dataWithHeaders = File.ReadAllLines(sourceFile);
int headerIndex = FindIndexOfHeader(dataWithHeaders);
string[] dataWithoutHeaders = new List<string>(dataWithHeaders)
.GetRange(headerIndex, dataWithHeaders.Length - headerIndex)
.ToArray();
[COLOR=red]File.WriteAllLines(sourceFile, dataWithoutHeaders);[/color]
Log.Info("removed headers. {0} rows remain.", dataWithoutHeaders.Length - 1);
}
Code:
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding)
at System.IO.File.WriteAllLines(String path, String[] contents, Encoding enco
ding)
at AccessControlDataImport.Con.Source.RemoveHeaders()
at AccessControlDataImport.Con.Source.GetDataFrom(String source)
at AccessControlDataImport.Con.Program.Main()
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission
The Zone of the assembly that failed was:
Intranet
Jason Meckley
Programmer
Specialty Bakers, Inc.