We help IT Professionals succeed at work.
Get Started

save file to network path + file encoding

ethar1 asked
Last Modified: 2015-12-06
Dear all,
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));

				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 					    

					//perform some recovery action here

Open in new window

when I run this code I got error :
Access to the path '\\xxxx\xxxxx\yyyyy\text.txt' is denied. at System.IO.__Error.WinIOError(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.
Watch Question
Software Architect
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE