winforms - Image Saving issue from Windows application c# -
i have developed win apps save images in specific folder our exe run from. below used save images
protected string getpath(string strfilename) { string strpath=system.environment.currentdirectory+@"\ups\labelimages\"; if (!system.io.directory.exists(strpath)) { system.io.directory.createdirectory(strpath); } strpath = strpath + strfilename; return strpath; }
the issue time win apps throwing execption
access path 'c:\windows\system32\ups\labelimages\' denied
suppose application installed inside c:\programfiles32
, throw kind of error c# exe file. tell me best option save image files result no user exception or error access path 'c:\windows\system32\ups\labelimages\' denied
looking suggestion.
i'd recommend saving files in safer location, such special folder application data:
var safefilepath = path.combine(environment.getfolderpath( environment.specialfolder.applicationdata), @"ups\labelimages");
from environment.specialfolder doc:
applicationdata: directory serves common repository application-specific data current roaming user.
you use location too, see fit (i.e. mydocuments
or mypictures
).
some locations on disk bad place try saving files because of potential access errors you're seeing, such "system32", "program files", or root c: directory, among others.
Comments
Post a Comment