permissions - Remote File Accessing from Sharepoint Application Page -


In my SharePoint application pages, I am trying to copy a file from a network shared folder .. and my The code is like below.

  try {file.Copy ("\\ MShare \ public \ Test.txt", "C: \ Temp \ Test.txt", true); LblMessage.Text = "File copied."; } Hold (Exception Pre) {LblMessage.Text = ex.ToString () + "-" + East message; }   

If I test the same code in ASP.NET website then it is working well. But I am having an error with the SP application page. .

  system. Agyatikrit Access Exchange: Path enter '\\ MShare \ Public \ Test.txt' disallowed System.IO on System.IO.File.InternalCopy on System.IO.File.Copy .__ Error.WinIOError (Int32 errorCode, String MaybeFullPath) (string SourceFileName, string destFileName, Boolean overwrite) (string SourceFileName, string destFileName, (object sender Boolean overwrite) at TestApp.PullingFile.ButGet_Click, EventArgs e) - path '\\ MShare \ Public \ Test.txt' Access is prohibited.   

I post've tried to implement impersonation by following .. not work .. and I tried to change the web.config with that & lt ; Confidence level = "WSS_Medium" originUrl = "" /> also ..

default SharePoint uses your code running under the current user's credentials. This user has not used the server's file system (and should not be used).

What you can do to access the file system:

  SPSecurity.RunWithElevatedPrivileges (() = & Gt; {file copy ("\\ MShare \ Public \ Test.txt "," C: \ Temp \ Test.txt ", true);});   

You have to keep in mind:

  1. System account (the application pool account) does not necessarily mean that the file system (less Less privileged scenario) ()
  2. The system account (application pool account) is not necessarily used to share the network.
  3. Any user can access your application page, your file can execute the copy code. You have to pay attention to the authorization yourself.

    Last but not least : Why do not you copy the file to the server's file system? Do you have it physically necessary on the server or it is just temporary (as can be guessed by path).

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -