In my Sharepoint Application Page, I'm trying to copy a file from a Network Shared Folder.. And my code's like below..
try
{
File.Copy("\\MShare\Public\Test.txt", "C:\Temp\Test.txt", true);
LblMessage.Text = "File copied.";
}
catch (Exception ex)
{
LblMessage.Text = ex.ToString() + " - " + ex.Message;
}
It's working well if I test the same code in ASP.NET Website.. But I'm getting error as follow with SP Application Page..
System.UnauthorizedAccessException: Access to the path '\\MShare\Public\Test.txt' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite) at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) at TestApp.PullingFile.ButGet_Click(Object sender, EventArgs e) - Access to the path '\\MShare\Public\Test.txt' is denied.
I've tried implementing impersonation by following this post.. Not working..
And I tried by changing at web.config with <trust level="WSS_Medium" originUrl="" />
also..