Prem Singh
Prem Singh

Reputation: 1035

Access to the path "*****" is denied

I have a folder in my same network as "\lo1dc\abcd\Admin\Images" I set full permission for everyone. I created a new web application in another machine within the same network and created a virtual directory called "_images" and set this folder path. I have set the path credential as a specified user while creating account and set the name as administrator. Which is administrator user for entire network.

Now while trying to save image as shown below

string strSaveLocationCode128 = Server.MapPath("~/_images") + "//abc.Jpg";
barcodeCode128Mobile.drawBarcode(strSaveLocationCode128);

This is showing me the error message as "Access to the path '\lo1dc\abcd\Admin\Images\abc.Jpg' is denied".

Please help me I am using Win 7 as my development platform.

Upvotes: 4

Views: 1983

Answers (2)

Prem Singh
Prem Singh

Reputation: 1035

Finally i found out the answer, The network path cannot be accessed by an anonymous user. So

SPSecurity.RunWithElevatedPrivileges

has done the trick for me. Thank you all for your valuable help at right time.

Upvotes: 3

Vano Maisuradze
Vano Maisuradze

Reputation: 5899

You can Login as local user using LogOnUser function:

        [DllImport("advapi32.dll", SetLastError = true)]
        private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

        // types 
        const int LOGON32_LOGON_INTERACTIVE = 2;
        const int LOGON32_LOGON_NETWORK = 3;
        const int LOGON32_LOGON_NEW_CREDENTIALS = 9;

        // providers 
        const int LOGON32_PROVIDER_DEFAULT = 0;
        const int LOGON32_PROVIDER_WINNT35 = 1;
        const int LOGON32_PROVIDER_WINNT40 = 2;
        const int LOGON32_PROVIDER_WINNT50 = 3;

Usage:

IntPtr token = IntPtr.Zero;
LogonUser("User Name", "Domain Name", "Password", LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_DEFAULT, ref token);

using (WindowsImpersonationContext user = new WindowsIdentity(token).Impersonate())
{
    // Do file operations here...
}

Upvotes: 0

Related Questions