1
votes

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.

3
There's a lot that depends on whether you expect this winform application to run on the SharePoint server itself or any computer at all. Which one are you doing?Reacher Gilt
The ultimate goal is to be able to access the libraries from any computer with authentication. However I am still learning SharePoint so any suggestions will be taken on board.Josh Price
Also is it possible to display the contents of the document library on a web page? As this would also fix my issue.Josh Price

3 Answers

3
votes

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

2
votes

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.

1
votes

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