none
getting files from a network share RRS feed

  • Question

  • Hello ,

    i have to get some files from a network share and upload it to sharepoint but my VM is not on that domain which authenticates for that network share...how can i explicitely pass user credentials in code to use to access that network share from my virtual machine.

     

    Thanks

    Tuesday, March 1, 2011 4:26 AM

Answers

  • Ok .. first of all, I would probably recommend that you don't try to manipulate network files from a web-server ... I can't think of a great reason to do this, and it's not a great idea from a security perspective.

    A more isolated process would be better (such as a Timer Job??)

    In terms of authentication, as I assume you are using the .Net System.IO namespace, you should use standard .Net Framework Impersonation techniques.

    This allows you to execute sections of your code using the credentials of another user (which should allow your System.IO.File/Directory classes to appropriately authenticate to the network share)


    regards
    Martin Hatch
    MCPD SharePoint 2010 | .Net Web Development
    MCTS WSS 3.0 | MOSS 2007
    Visit my Blog - www.martinhatch.com
    • Marked as answer by Wayne Fan Friday, March 11, 2011 6:46 AM
    Tuesday, March 1, 2011 9:23 AM
  • You will have to explicitly logon as an authenticated user to the file share and execute your code. You can read more and get an example of this at the link below:

    http://pinvoke.net/default.aspx/advapi32.LogonUser


    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    • Marked as answer by Wayne Fan Friday, March 11, 2011 6:46 AM
    Tuesday, March 1, 2011 3:34 PM

All replies

  • Ok .. first of all, I would probably recommend that you don't try to manipulate network files from a web-server ... I can't think of a great reason to do this, and it's not a great idea from a security perspective.

    A more isolated process would be better (such as a Timer Job??)

    In terms of authentication, as I assume you are using the .Net System.IO namespace, you should use standard .Net Framework Impersonation techniques.

    This allows you to execute sections of your code using the credentials of another user (which should allow your System.IO.File/Directory classes to appropriately authenticate to the network share)


    regards
    Martin Hatch
    MCPD SharePoint 2010 | .Net Web Development
    MCTS WSS 3.0 | MOSS 2007
    Visit my Blog - www.martinhatch.com
    • Marked as answer by Wayne Fan Friday, March 11, 2011 6:46 AM
    Tuesday, March 1, 2011 9:23 AM
  • You will have to explicitly logon as an authenticated user to the file share and execute your code. You can read more and get an example of this at the link below:

    http://pinvoke.net/default.aspx/advapi32.LogonUser


    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    • Marked as answer by Wayne Fan Friday, March 11, 2011 6:46 AM
    Tuesday, March 1, 2011 3:34 PM