0
votes

I have following code from http://ktskumar.wordpress.com/2009/03/03/upload-document-from-local-machine-to-sharepoint-library/ to upload a document to a sharepoint library using web services. I have added https://mysite.sharepoint.com/_vti_bin/Copy.asmx (this site is on sharepoint Online) as my service reference.

     //Copy WebService Settings
        string webUrl = "https://mySite.sharepoint.com";

        WSCopy.Copy copyService = new WSCopy.Copy();

        copyService.Url = webUrl + "/_vti_bin/copy.asmx";
        copyService.Credentials = System.Net.CredentialCache.DefaultCredentials;

        //Source and Destination Document URLs
        string sourceUrl = "http://localhost/Shared Documents/Sample.doc";
        string destinationUrl = "E:\\DocumentsSample.doc";

        //Variables for Reading metadata’s of a document
        WSCopy.FieldInformation fieldInfo = new WSCopy.FieldInformation();
        WSCopy.FieldInformation[] fieldInfoArray = { fieldInfo };
        WSCopy.CopyResult cResult1 = new WSCopy.CopyResult();
        WSCopy.CopyResult cResult2 = new WSCopy.CopyResult();
        WSCopy.CopyResult[] cResultArray = { cResult1, cResult2 };

        //Receive a Document Contents  into Byte array (filecontents)
        byte[] fileContents = new Byte[4096];
        uint copyresult = copyService.GetItem(sourceUrl, out fieldInfoArray, out fileContents);

        if (copyresult == 0)
        {
            Console.WriteLine("Document downloaded Successfully, and now it's getting saved in location " + destinationUrl);

            //Create a new file and write contents to that document
            FileStream fStream = new FileStream(destinationUrl, FileMode.Create, FileAccess.ReadWrite);
            fStream.Write(fileContents, 0, fileContents.Length);
            fStream.Close();

        }
        else
        {
            Console.WriteLine("Document Downloading gets failed...");
        }

        Console.Write("Press any key to exit...");
        Console.Read();

here WSCopy is the service reference and 'WSCopy.Copy' copy class is not found on my project. How can i resolve this or is there another way to achive my goal.

1
I think asmx web services are deprecated in SP 2013Flowerking
It's not very clear what you want to do here... So a user will go to the Sharepoint and then click somewhere to browse his local folders to pick a file, and then it will upload the file to the Sharepoint? If it's why you're trying to achieve, then you may want to look at this : SharepointPlus createFile ; you'll have to use the [html5rocks.com/en/tutorials/file/dndfiles/](HTML5 File API) or a Flash solution for old browsers... If it's not what you're trying to do, then please explain again :-)AymKdn
Hi I am stuck in a similar issue, How did you over come?Akshay

1 Answers

1
votes

Refer to this post http://www.ktskumar.com/blog/2009/03/upload-document-from-local-machine-to-sharepoint-library/

You have to add the web service url in Web Reference, instead of Service Reference. On Visual Studio Project, Right click the References, and select the Add Service Reference. On Add Service Reference popup, click the Advanced button on bottom of the box, Now the Service Reference Settings popup will open, there we have to click the “Add Web Reference” botton. Then give the Web Service url and click the “Add Reference” button to include webservice url to the project.