Graham
Graham

Reputation: 41

Pass Parameter Upload.aspx Sharepoint Online

I can't believe this is so hard!

So put simply i am trying to upload a document in Sharepoint with some data being passed in the link.

A little more detail: I'm trying to integrate Sharepoint with Salesforce. In Salesforce I have a link to view an objects documents that uses the following to filter on Sharepoint: .../Shared%20Documents/Forms/AllItems.aspx?FilterField1=SalesforceID&FilterValue1=SALESFORCEID

I have then provided another link that allows the user to upload a document using the following: .../_layouts/15/Upload.aspx?List=LISTGUID

I have then made the SalesforceID column mandatory so that when the user finishes the upload they are presented with the EditForm.aspx where they can input the SalesforceID to associate the document to the Salesforce object. This works pretty well but would be a little slicker if the SalesforceID could be populated automatically.

I started with the following .../_layouts/15/Upload.aspx?List=LISTGUID&SalesforceID=SALESFORCEID

Once you've selected the file to upload and hit ok it takes you to the following which shows the field value being passed on but unfortunately does not populate the required field .../Shared%20Documents/Forms/EditForm.aspx?Mode=Upload&CheckInComment=&ID=9718&RootFolder=%2FROOTFOLDER%2FShared%20Documents&SalesforceID=SALESFORCID

So I started looking into editing the Upload.aspx or EditForm.aspx to accommodate this. This doesn't appear to be possible on Sharepoint online though.

So I started looking into creating a custom page. So i'm pretty good at C# and have already written something that can upload and set metadata in Sharepoint but you cannot run server side code on Sharepoint online.

So I have now been looking into doing this via javascript (https://blogs.msdn.microsoft.com/uksharepoint/2013/04/20/uploading-files-using-the-rest-api-and-client-side-techniques/) and am just getting "Access denied. You do not have permission to perform this action or access this resource."

If anyone has had any success with any of the approaches above I would love to know how you managed to get it working. For the amount of time i'm spending on trying to fix this and how much time it's actually going save our users I'm ready to give up.

Upvotes: 1

Views: 3148

Answers (1)

Graham
Graham

Reputation: 41

For reference and anyone else struggling as I did with this I managed to eventually find a solution.

Firstly on the online Sharepoint it does not look like you can amend Upload.apsx but you can amend the EditForm.aspx. After you upload the file you will be directed to this form to make it work.

So you want to pass the parameter to Upload.aspx, upon posting it will get passed to EditForm.aspx (but a custom one) and you can use the parameter in the form.

Here's how to do it:

  • Open up you site in Sharepoint designer
  • Go to Lists and Libraries and click on the Documents library
  • You should get a sort of summary page with several sections one of which is Forms
  • Under the Forms section click New
  • Give it a File Name (customedit)
  • Select "Edit item form (used to edit existing list items)"
  • Select "Set as default form for the selected type" as this will override the EditForm.aspx from being used once the user clicks to upload the file
  • Click OK
  • Your new form will appear in the Forms section
  • Click on it to edit the file
  • First we need to define the parameter in the form
  • Click in the code either in the WebPartPages:DataFormWebPart tag (line 24 on mine) or below to get the location specific options at the top
  • In the top ribbon you should now see Data View Tools
  • Click on Options and in the Filter, Sort & Group section click Parameters
  • Click on New Parameter and type in the Query String Variable (the field id you are passing in the address) and the Default Value
  • It will call it Param1 which you can optionally change but i haven't for the below
  • Scroll down until you see (was line 122 on mine)
  • Below it should be a table containing your documents fields
  • Delete those you don't want to see to tidy up your edit form
  • Under the item you want to auto-populate you should see a SharePoint:FormField tab that looks like this <SharePoint:FormField runat="server" id="ff1{$Pos}" ControlMode="Edit" FieldName="SalesforceID" __designer:bind="{ddwrt:DataBind('u',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@SalesforceID')}"/>
  • Make a note of the ff number (ff1 in the above)
  • You want to replace this with <asp:TextBox runat="server" id="ff1{$Pos}" value="{$Param1}" text="" __designer:bind="{ddwrt:DataBind('u',concat('ff1',$Pos),'Text','TextChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@SalesforceID')}"/>
  • Replace the ff1 with the number you made a note of in the previous point
  • Replace SalesforceID with the field name of your Sharepoint column
  • Save and test

Now I figured this out a while ago but wanted to post this for reference so if it doesn't work I may have missed a point but hopefully you get the gist of it.

All that's left for me is figuring out how to auto-populate a unique filename or stop overwriting files. Both I'm failing at miserably

Upvotes: 1

Related Questions