Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

When a user uploads/creates a document into my document library, i need to be able to apply a metadata tag to the document either from the URL query string or from the value selected in some web-part that is also on the page.

Here is the full explanation: I want to build a web-part that reads from a list and presents a hierachical navigation tree, the bottom level nodes will map to terms in the term-store and will be links to document libraries. Multiple bottom level nodes can point to the same library. When a user clicks a bottom level node they are taken to the relevent library for that node, when they create/upload a document the appropriate metadata term (that they clicked on in the navigation tree) will be applied to the document (they can't then change it).

Does anyone have any ideas how this might be done? I thought of adding a query string to the URL but not sure how to then apply the term to the item.

I also thought of creating a custom field that would be applied to the content type of the documents being uploaded but i don't think that the code in the field would be able to 'reach' up onto the page to grab the selected value from the navigation control or get it from the URL either.

Finally i thought of an event receiver on the doc library, but again i'm not sure how to obtain the term that needs to be applied to the document,

Any help would be appreciated,

Thanks

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

If you want to use query string parameters to set metadata, you're going to need some script that parses the query string and sets the field values. I've done this in the past with jQuery and SPServices. Marc has created a dead simple to use query string parser in the SPServices project.

Here's an example from a project I worked on that got 2 query string variables and set field values with them.

<script type="text/javascript">
$(document).ready(function(){

var queryStringVals = $().SPServices.SPGetQueryString();
var IDtoGet = queryStringVals["theCID"];
var insEmail = queryStringVals["InstructorEmail"];
  $("textarea[Title$='People Picker']").val(insEmail);
  $("div[title='People Picker']").text(insEmail); 
}); //close doc ready
</script> 
share|improve this answer
    
Thanks @Kit Menke and both of you for your suggestions, but how would I apply this within a document library? I believe that the upload form is a physical file (upload.aspx in the layouts directory). I don't want to edit it directly as i think this will effect the whole farm. If i make a copy and change that, how would specify that specific libraries use the new upload page and not the default one? Also for when a use creates a new document from the library i guess i would need to use another approach, any ideas? THanks for your help, really appreciated :-) –  toby Aug 5 '11 at 10:21
    
I'm pretty sure the upload page redirects to EditForm.aspx.. –  Kit Menke Aug 5 '11 at 14:16
    
It does, that's where you can do some client side scripting. –  PirateEric Aug 5 '11 at 14:52
    
Thanks guys, will take a look. Thanks for your help. –  toby Aug 5 '11 at 16:33
add comment

As @PirateEric mentioned, an easy way to set metadata fields using a query string is by using JavaScript. I maintain SPUtility.js which can help with setting and getting SharePoint fields. For example:

SPUtility.GetSPField('Document Category').SetValue(urlValue).MakeReadOnly();

You probably won't be able to use an event receiver because it won't have access to a query string parameter (see How to retrieve the querystring in Sharepoint itemadded event).

See also: Autopopulate a SharePoint Form from URL (with SPUtility.js) (my blog)

share|improve this answer
    
Thanks very much Kit, really appreciate your input and will take a look at SPUtility, impressed that this can be done in a one liner. Additional comments on PriateEric's post. –  toby Aug 5 '11 at 10:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.