Get Folder Name of Current Document in Document Library

Jul 23, 2012 at 2:29 PM

I have users who upload documents to certain folders in a document library.  Each folder has default meta-data associated with it.  To make the tagging process easier for the uploaders, I would like to pre-select the default values based on the folder the document is in.  Is there a way through SPServices or just jQuery that I can get the folder name so that when the user is in the edit form, I can use that value to preselect the defaults?

I've looked at the source of the edit page and other than the breadcrumb fields, I can't see a reference to the file.  

Marc mentioned the fileref via twitter but I am not sure how to get that value.

Thanks

Dave Petersen

Jul 23, 2012 at 4:19 PM

When you are filling out the form for document(s), the document has already uploaded to the site.  So on your edit form, if you use the web services to query the doc library for the most recently uploaded document(s) by the current user, you'll get the FileRef that Marc was referring to.  

Once you have that, you can parse that URL to determine the folder structure the document(s) reside in and then query your library again to get the metadata for that folder. Or at least you *should* be able to.... 

 

Cheers,
Matt 

Coordinator
Jul 24, 2012 at 3:42 AM

Matt's got the right idea. The file is already uploaded, and you're on the EditForm,right? You also have the item's ID on the Query String, so you can use GetListItems to get everything known about that item so far. The most recently uploaded could in theory get you into trouble if the user has multiple browser windows open and uploads more than one document at a time. (I sometimes do this, so I always try not to code things that would break because of it.)

M.

Jul 24, 2012 at 4:36 AM
That's a great idea. The one thing I hate about the upload process is that the document exists before any of the meta data! Now, it just may help me! :) I'll play around with it and see what I come up with.

Thanks
Dave

On Mon, Jul 23, 2012 at 9:42 PM, sympmarc <notifications@codeplex.com> wrote:

From: sympmarc

Matt's got the right idea. The file is already uploaded, and you're on the EditForm,right? You also have the item's ID on the Query String, so you can use GetListItems to get everything known about that item so far. The most recently uploaded could in theory get you into trouble if the user has multiple browser windows open and uploads more than one document at a time. (I sometimes do this, so I always try not to code things that would break because of it.)

M.

Read the full discussion online.

To add a post to this discussion, reply to this email (SPServices@discussions.codeplex.com)

To start a new discussion for this project, email SPServices@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com