locked
Remote upload into sharepoint 2013 document library (cloud based) RRS feed

  • Question

  • We have a sharepoint 2013 in the cloud.

    Is it possible to have some kind of service (windows or web based) that can access a document library on said cloud server and put files into said document library?

    I don't think we have a lot of behind the scenes access to the cloud instance of 2013.

    Thursday, July 17, 2014 2:34 PM

Answers

  • Hi,

    As I said above, we could use the Client Object Model to upload the files without the user having to go to SharePoint in the browser first and logging in.

    We can use the credentials in the code as below, the code would copy files to SharePoint online, it worked well in my environment, you can check whether it works.

    public static void CopyDocuments(string srcUrl, string srcLibrary, string destUrl, string destLibrary)
    
            {
    
                
    
                // set up the src client
    
                ClientContext srcContext = new ClientContext(srcUrl);
    
                SecureString passWord1 = new SecureString();
    
    
                foreach (char c in "Password01!".ToCharArray()) passWord1.AppendChar(c);
    
    
                srcContext.Credentials = new SharePointOnlineCredentials("v-jaguo@milesli.onmicrosoft.com", passWord1);
    
    
                
    
    
                Web srcWeb = srcContext.Web;
    
                List srcList = srcWeb.Lists.GetByTitle(srcLibrary);
    
                ListItemCollection itemColl = srcList.GetItems(new CamlQuery());
    
                srcContext.Load(itemColl);
    
                srcContext.ExecuteQuery();
    
    
                
    
    
                // set up the destination context
    
                ClientContext destContext = new ClientContext(destUrl);
    
               SecureString passWord = new SecureString();
    
    
                foreach (char c in "Password01!".ToCharArray()) passWord.AppendChar(c);
    
    
                destContext.Credentials = new SharePointOnlineCredentials("v-jaguo@milesli.onmicrosoft.com", passWord);
    
    
                // get the destination list
    
                Web destWeb = destContext.Web;
    
                destContext.Load(destWeb);
    
                destContext.ExecuteQuery();
    
    
                foreach (var doc in itemColl)
    
                {
    
                    try
    
                    {
    
                        //if (doc.FileSystemObjectType == FileSystemObjectType.File) //Field or Property "FileAttachement not found."                    
    
                        //{
    
                        // get the file
    
                        File file = doc.File;
    
                        srcContext.Load(file);
    
                        srcContext.ExecuteQuery();
    
    
                        // build destination url
    
                        string nLocation = destWeb.ServerRelativeUrl.TrimEnd('/') + "/" + destLibrary.Replace(" ", "") + "/" + file.Name;
    
    
                        // read the file, copy the content to new file at new location
    
                        FileInformation fileInfo = File.OpenBinaryDirect(srcContext, file.ServerRelativeUrl);
    
                        File.SaveBinaryDirect(destContext, nLocation, fileInfo.Stream, true);
    
                        // }
    
    
    
                    }
    
                    catch (Exception ex)
    
                    {
    
                                    
    
                    }
    
                }
    
            }
    

    http://blog.blumshapiro.com/blog/2012/08/22/sharepoint-2010-using-the-client-object-model-to-move-files-and-folders-across-site-collections-and-subsites/

    Thanks,
    Jason
    Forum Support Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Jason Guo
    TechNet Community Support

    • Marked as answer by Lindali Sunday, July 27, 2014 1:15 PM
    Wednesday, July 23, 2014 1:33 AM

All replies

  • Yea the new way of asking questions to the Microsoft community is not easy.

    But try your question in a Sharepoint forum.

    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/home?forum=sharepointdevelopment


    Success
    Cor

    Thursday, July 17, 2014 3:10 PM
  • i was directed to here from technet.......
    Thursday, July 17, 2014 4:58 PM
  • Hi,

    According to your post, my understanding is that you wanted to upload files to SharePoint 2013 library.

    Did you mean you use the SharePoint online?

    To upload the files to SharePoint library, we can use the out of the box feature “Open with Explorer”.

    We can also use the SharePoint Client Side Object Model or REST API to upload files to SharePoint library.

    To upload files using Client Side Object Model, you can refer to the following articles.

    http://blogs.msdn.com/b/sridhara/archive/2010/03/12/uploading-files-using-client-object-model-in-sharepoint-2010.aspx

    http://www.codeproject.com/Articles/103503/How-to-upload-download-a-document-in-SharePoint-20

    To upload files using REST API, you can have a look at the following artilces.

    http://msdn.microsoft.com/en-us/library/office/dn769086(v=office.15).aspx

    http://blogs.msdn.com/b/uksharepoint/archive/2013/04/20/uploading-files-using-the-rest-api-and-client-side-techniques.aspx

    Thanks,
    Jason
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Jason Guo
    TechNet Community Support

    Friday, July 18, 2014 3:25 AM
  • You can use the CSOM, check out my free community tool at http://sharepointdragons.com/2013/05/10/the-migration-dragon-for-sharepoint-2013/ to see example code

    Kind regards,
    Margriet Bruggeman

    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com

    Friday, July 18, 2014 6:02 AM
  • best way to explain is.

    On a server machine on our end, we want to create a window service that can monitor a folder for new files. When a file shows up, it would do whatever it needs to do and then move the file into a document library on sharepoint online.

    We need to be able to have it use specific credentials to do the upload. These credentials obviously will exist on the sharepoint side of things.

    This has to possible without having to into the browser and logging in + trusting a dozen sites. can't do that on a server.

    Friday, July 18, 2014 11:40 AM
  • so, forgetting about using specific credentials, how can I have, say a windows form application, on a client machine access sharepoint without the user having to go to sharepoint in the browser first and logging in?

    Are there any good and complete code examples out there that explain how to do that if it is even possible.

    again, we do not host sharepoint 2013, it is a cloud based instance. We do not have any kind of admin rights to it.

    authentication is the sticking point here, not actually moving the files.

    • Edited by Zenuke Monday, July 21, 2014 3:52 PM
    Monday, July 21, 2014 3:50 PM
  • Hi,

    As I said above, we could use the Client Object Model to upload the files without the user having to go to SharePoint in the browser first and logging in.

    We can use the credentials in the code as below, the code would copy files to SharePoint online, it worked well in my environment, you can check whether it works.

    public static void CopyDocuments(string srcUrl, string srcLibrary, string destUrl, string destLibrary)
    
            {
    
                
    
                // set up the src client
    
                ClientContext srcContext = new ClientContext(srcUrl);
    
                SecureString passWord1 = new SecureString();
    
    
                foreach (char c in "Password01!".ToCharArray()) passWord1.AppendChar(c);
    
    
                srcContext.Credentials = new SharePointOnlineCredentials("v-jaguo@milesli.onmicrosoft.com", passWord1);
    
    
                
    
    
                Web srcWeb = srcContext.Web;
    
                List srcList = srcWeb.Lists.GetByTitle(srcLibrary);
    
                ListItemCollection itemColl = srcList.GetItems(new CamlQuery());
    
                srcContext.Load(itemColl);
    
                srcContext.ExecuteQuery();
    
    
                
    
    
                // set up the destination context
    
                ClientContext destContext = new ClientContext(destUrl);
    
               SecureString passWord = new SecureString();
    
    
                foreach (char c in "Password01!".ToCharArray()) passWord.AppendChar(c);
    
    
                destContext.Credentials = new SharePointOnlineCredentials("v-jaguo@milesli.onmicrosoft.com", passWord);
    
    
                // get the destination list
    
                Web destWeb = destContext.Web;
    
                destContext.Load(destWeb);
    
                destContext.ExecuteQuery();
    
    
                foreach (var doc in itemColl)
    
                {
    
                    try
    
                    {
    
                        //if (doc.FileSystemObjectType == FileSystemObjectType.File) //Field or Property "FileAttachement not found."                    
    
                        //{
    
                        // get the file
    
                        File file = doc.File;
    
                        srcContext.Load(file);
    
                        srcContext.ExecuteQuery();
    
    
                        // build destination url
    
                        string nLocation = destWeb.ServerRelativeUrl.TrimEnd('/') + "/" + destLibrary.Replace(" ", "") + "/" + file.Name;
    
    
                        // read the file, copy the content to new file at new location
    
                        FileInformation fileInfo = File.OpenBinaryDirect(srcContext, file.ServerRelativeUrl);
    
                        File.SaveBinaryDirect(destContext, nLocation, fileInfo.Stream, true);
    
                        // }
    
    
    
                    }
    
                    catch (Exception ex)
    
                    {
    
                                    
    
                    }
    
                }
    
            }
    

    http://blog.blumshapiro.com/blog/2012/08/22/sharepoint-2010-using-the-client-object-model-to-move-files-and-folders-across-site-collections-and-subsites/

    Thanks,
    Jason
    Forum Support Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Jason Guo
    TechNet Community Support

    • Marked as answer by Lindali Sunday, July 27, 2014 1:15 PM
    Wednesday, July 23, 2014 1:33 AM