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
}
Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>
Our community of experts have been thoroughly vetted for their expertise and industry experience.