Getting list of files in a folder on SharePoint 2010 using Visual Studios 2010 asp.net

Is it possible for me to get a list of files that are in a sub folder on SharePoint without being on the server that SharePoint is on?
hscastAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hscastAuthor Commented:
I cant test it until Monday, but that looks like what I was looking for.
0
hscastAuthor Commented:
In that example you linked, could you help me figure out what my "rootList" would be.

Below is a link to the folder I need to get the files from.  Customer Specs is the name of the folder

http://portal/sites/lab/Department%20Documents/Forms/AllItems.aspx?RootFolder=%2Fsites%2Flab%2FDepartment%20Documents%2FSpecifications%2FCustomer%20Specs
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Daniel KlineSr. SharePoint DeveloperCommented:
0
hscastAuthor Commented:
Okay so I'm getting this error.

List 'http://hsportal/sites/metlab/Department%20Documents/Specifications' does not exist at site with URL 'http://hsportal'.

Here's my code, can you see what I have wrong?

 
       ClientContext cc = new ClientContext("http://portal");
        List partsList = cc.Web.Lists.GetByTitle("http://portal/sites/lab/Department%20Documents/Specifications");
        CamlQuery camlQueryPartsList = new CamlQuery();
        camlQueryPartsList.ViewXml =
          @"<View>
        <Query>
        </Query>
      </View>";
        camlQueryPartsList.FolderServerRelativeUrl = "/Customer Specs";
        Microsoft.SharePoint.Client.ListItemCollection listItems = partsList.GetItems(camlQueryPartsList);
        cc.Load(listItems);
        cc.ExecuteQuery();

Open in new window

0
Daniel KlineSr. SharePoint DeveloperCommented:
My typo on my phone.  Just Portal. Not hPortal.
0
hscastAuthor Commented:
oh yeah I had that part right. It's still giving me the error. Do you see anything else wrong?
0
hscastAuthor Commented:
I used this code I found online to return a list of all lists from the server

 string siteURL = "http://portal/sites/lab/";
        ClientContext context = new ClientContext(siteURL);

        // The SharePoint web at the URL.
        Web web = context.Web;
        
        // Retrieve all lists from the server. 
        context.Load(web.Lists,
                     lists => lists.Include(list => list.Title, // For each list, retrieve Title and Id. 
                                            list => list.Id));

        // Execute query. 
        context.ExecuteQuery();

        // Enumerate the web.Lists. 
        foreach (List list in web.Lists)
        {
            label1.Text = label1.Text + "<p> " + list.Title;
        } 

Open in new window


and in that list I find "Department Documents" which has a folder that has the folder I need. I get that list when its just the above url, but if I add "Department Documents" to the end there I get this error.

Cannot contact site at the specified URL http://portal/sites/lab/Department Documents. There is no Web named "/sites/lab/Department Documents/_vti_bin/sites.asmx".

Not sure if this will help you help me, but it's as far as I have gotten. Thanks for your help!
0
Daniel KlineSr. SharePoint DeveloperCommented:
I think I'm seeing your confusion.   Sorry it took so long to get back to you.

Is the root of the site collection http://portal/sites and all the sites are sub sites?
And one of your sites is Lab
And it contains a Document Library named "Department Documents"
Which contains a subfolder named "Customer Specs"

And what you want is a listing of the files in the Customer Specs folder.
I'm trying to guess at the architecture of your farm.

The Sites.asmx services you are trying to reach should be at be at
    http://portal/sites/_vti_bin/sites.asmx
if http://portal/sites points to the root of the  site collection and the web application.

if you paste that url into you browser, it should return a page to the soap service endpoints.  You should see a listing of the listeners.  

Try setting the site url as "http://portal/sites/"  Then use the getsites service to return the lab site.

Then you continue to traverse the hierarchy through the lists to Department Documents and finally get the Customer Specs list which you iterate.

I usually use the rest services (oData) and the JavaScript client object model for these tasks.  I find it much easier.

Use your debugger to view the contents of the object as you are accessing them.  It will help expose the methods to retrieve the next level of the object model.  It's like peeling an onion.
0
hscastAuthor Commented:
So there doesn't seem to be a root collection of sites. http://portal is the root and to get to the lab it tacks on /sites/lab, but there is no just http://portal/sites.

file structure in web browser
http://portal   
                  |_   /sites/lab
                                |_   /Department Documents (folder)
                                                                      |_        /Specifications (sub folder)
                                                                                                 |_      /Customer Specs (sub sub folder and where the files i want to get are)


I can get into http://portal/sites/lab and see what is in there, but I cant seem to go any further in.

And I just want to make sure I made this clear. I'm developing on a different server than SharePoint and on an intranet page that will just retrieve the file names from a sub folder. I am also using the sharepoint client object model ddl. Thanks again for all your help.
0
Daniel KlineSr. SharePoint DeveloperCommented:
Great.  The complexity of what you are trying to do is one of the reasons I avoid foldering unless absolutely necessary.

You say you get to "lab".   Is Sites a sub site and lab a sub site of lab?

I'm stretching here, but can you set the web context to "lab" and then traverse the lists in the sub site as if they were a root site?

You could also resolve the issue with a little re-architecting.  Export the folder contents and import them into the site at the root level.  Use metadata to accomplish what you are trying to do with foldering.   Folders really are evil.

Sorry.  I couldn't find an example of what you are trying to accomplish.
0
hscastAuthor Commented:
When I try to access http://portal/sites I get 404 error, but if I can go to  http://portal/sites/lab. It's my understanding that  http://portal/sites/lab is it's own site. So what my problem seems to be I can't access the sub directories of a site. When I do I get that error that I have posted before.
0
hscastAuthor Commented:
I think I found a work around. I'm not using the API anymore and just going straight to the directory and grabbing the file names from there.
0
Daniel KlineSr. SharePoint DeveloperCommented:
Hmmm.  That intrigues me.  The directory is built in the Virtual Path provider.  How are you doing it.
0
hscastAuthor Commented:
 string[] filepaths = Directory.GetFiles("\\\\portal\\DavWWRoot\\sites\\lab\\Department Documents\\Specifications\\Customer Specs");
    protected void Page_Load(object sender, EventArgs e)
    {        

        for (int i = 0; i < filepaths.Length; i++)
        {
            int last = filepaths[i].LastIndexOf('\\');
            label1.Text = label1.Text + filepaths[i].Substring(last + 1);
        }
    }

Open in new window

0
Daniel KlineSr. SharePoint DeveloperCommented:
Ahhh.  Clever.  I didn't think of WeDav.  Nice job.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hscastAuthor Commented:
I found a work around
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.