c# - Access to the path Denied when uploading excel file -
when uploading excel file receiving error, can me?
access path 'c:\data\ironelements\upload\aumdata\20101202 031815.xlsx' denied. description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.
exception details: system.unauthorizedaccessexception: access path 'c:\data\ironelements\upload\aumdata\20101202 031815.xlsx' denied.
asp.net not authorized access requested resource. consider granting access rights resource asp.net request identity. asp.net has base process identity (typically {machine}\aspnet on iis 5 or network service on iis 6) used if application not impersonating. if application impersonating via , identity anonymous user (typically iusr_machinename) or authenticated request user.
to grant asp.net access file, right-click file in explorer, choose "properties" , select security tab. click "add" add appropriate user or group. highlight asp.net account, , check boxes desired access.
source error:
an unhandled exception generated during execution of current web request. information regarding origin , location of exception can identified using exception stack trace below.
my code behind file has following syntax
datetime date = datetime.now; string filename = convert.tostring(date.tostring("yyyymmdd hhmmss")); directory.createdirectory("c:\\data\\ironelements\\upload\\aumdata\\schema"); doesfileexists("c:\\data\\ironelements\\upload\\aumdata\\schema"); fileupload.postedfile.saveas("c:\\data\\ironelements\\upload\\aumdata\\" + filename + ".xlsx"); system.threading.thread.sleep(5000); string connectionstring = webconfigurationmanager.connectionstrings["sqlconnection"].connectionstring; sqlconnection sqlconnect = new sqlconnection(connectionstring); try { sqlconnect.open(); sqlcommand cmdassetundermanagement = new sqlcommand("exec_insert_aumassetvalue", sqlconnect); cmdassetundermanagement.commandtype = commandtype.storedprocedure; cmdassetundermanagement.executenonquery(); } catch (exception ex) { response.write(ex.message); } { sqlconnect.close(); } lblaumta.visible = true; lblaumta.text = "file upload completed"; } private void doesfileexists(string p) { p = string.concat(p, "\\aumschema.xlsx"); if (!file.exists(p)) { fileupload.postedfile.saveas("c:\\data\\ironelements\\upload\\aumdata\\schema\\aumschema.xlsx"); } }
make sure folder c:\data\ironelements\upload\aumdata has ntfs write permission user in context iis executes. please make sure subfolders of c:\data\ironelements\upload inherits permissions it's parent. this, click advanced button security tab -> change permissions -> check replace child object permissions inheritable permissions object -> hit ok
Comments
Post a Comment