Reputation: 41
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
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:
<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')}"/>
<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')}"/>
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