Domanda

Is it possible to access a SharePoint 2010 document library from a web application? If so then could you point me in the right direction?

I need to write an application that will allow document versioning, check in/check out, download/upload and searching.

So far I have written a basic Windows Forms application that can do all of the functions mentioned previously but now I need to access them from a web application.

È stato utile?

Soluzione

From a Windows Forms application, you can use the managed client object model to access SharePoint document libraries, etc. See this link for more information:

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

Altri suggerimenti

First you should check what you want to expose to the webapplication. Will this webapplication be a public facing (over the internet) application? Or will it be used internally only.

When it will only be used internally, I would make sure the webapplication can access the default webservices of SharePoint and can query the document library with the help of this service. An example of this method you can find here: Using SharePoint Web Services to Explore Document Libraries

If it is a public facing webservice you should check how much of the functionality you'll need. Because this would mean that you would also have to expose your SharePoint services to the internet. Another option could be writing your own service which implements the needed functionality and then just expose that service. This will lower your security risk and maybe you can reuse some of the code that you used in your Windows Forms application and move it to the service.

First you need to add reference to Microsoft.SharePoint.dll.

Here is sample code how you can access items inside document library:

        using (SPSite site = new SPSite("SiteUrl"))
        {
            using (SPWeb web = site.OpenWeb())
            {
                web.AllowUnsafeUpdates = true;
                //documentCategories is list of doc library names on SPSite, so catName  could be something like "Invoices"
                foreach (string catName in documentCategories)
                {
                    SPFolder folder = GetFolder(web, catName, processInstanceId, false);
                    if (folder.Exists)
                    {
                        //handle specific document...
                        foreach (SPFile file in folder.Files)
                        {

                        }
                    }
                }
                web.Close();
            }
            site.Close();
        }

Well this is just basic to get you started. Take notice you have to have windows authentication and impersonation enabled inside your web page to access SPSite with actual user creadentials or you can impersonate specific user, what is not a good practice.

For more tech details visit:

SPSite

SPWeb

SPFile

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top