ethar turky
asked on
save file to network path + file encoding
Dear all,
need to correct this code , to save file to network path :
when I run this code I got error :
Access to the path '\\xxxx\xxxxx\yyyyy\text.t xt' is denied. at System.IO.__Error.WinIOErr or(Int32 errorCode, String maybeFullPath) 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, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor (String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor (String path, FileMode mode) in :line 319
Also how to set file encoding.
Thanks
need to correct this code , to save file to network path :
var permissionSet = new PermissionSet(PermissionState.None);
var writePermission = new FileIOPermission(FileIOPermissionAccess.Write , string.Format("{0}/{1}", sPath, FileName));
permissionSet.AddPermission(writePermission);
if (permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
{
using (FileStream fstream = new FileStream(String.Format("{0}/{1}", sPath, FileName) , FileMode.Create ))
using (StreamWriter writer = new StreamWriter(fstream ))
{
// try catch block for write permissions
writer.WriteLine(contents);
}
}
else
{
//perform some recovery action here
}
when I run this code I got error :
Access to the path '\\xxxx\xxxxx\yyyyy\text.t
Also how to set file encoding.
Thanks
ASKER
yes it work manually perfect .
the application hosted on IIS and try to access a shard folder.
I also map the shared folder to a drive put still face same problem
the application hosted on IIS and try to access a shard folder.
I also map the shared folder to a drive put still face same problem
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you sure you have correct access permissions set up on network to the drive you are trying to write to? I mean is the path '\\xxxx\xxxxx\yyyyy\" correct? Can you open windows explorer and type this path and see if you are able to open it without any access errors? Also if it open up, can you right click in the windows explorer and try creating a text file with some contents in it and save it? Does that work manually for you?
Open in new window