0

In SharePoint 2010, I have a Wiki page that includes a button. When the user clicks on it, they head to Upload.aspx for a document library to submit a document. Once finished, when they fill in column values and click "OK", usually they're then presented with the document they uploaded. I want them to go back to the original wiki page where they clicked the button.

Searching for related questions, I've found that a Source attribute can be added, the trouble is that this doesn't appear to be working. For example, when my button is linked this way:

<a href='(...long url...)/DocumentLibrary/Upload.aspx?Source=url_encoded_url_for_wiki_page'> (...) </a>

The behavior that I see is that post document upload, the user is returned to the Document Library default view, not the link I provided. Now, if Source is absent or blank, the user goes to the uploaded file itself, so clearly something is happening. I've tried both a fully-qualified URL, and just a relative path such as /sites/blahblah/Wiki%20Pages/Home.aspx, both with the same result.

What's going on with the Source parameter here?

1

Below is some of the reflectored code from upload.aspx. Notice that if the file is checked out it will redirect to the file itself. So you might need to make sure you don't have any required columns. Other than that it should use the source or the default view (see SPRedirectFlags.UseSource below). Since you are being redirected to the default view, my gut tells me that your source isn't quite correct or isn't making it to the page. Maybe use fiddler to check and verify that there aren't any redirects going on which is losing your source querystring.

if ((this.IsSimpleList && sPFile.Level != SPFileLevel.Checkout) || sPFile.Item == null)
{
    if (base.IsDialogMode)
    {
        if (this.IsSolutionCatalog && sPFile.Name != null && sPFile.Name.Length > 4 && sPFile.Name.Substring(sPFile.Name.Length - 4).ToLower(CultureInfo.InvariantCulture) == ".wsp")
        {
            this.OnSubmitSolution(sPLongOperation, sPFile);
        }
        else
        {
            string serverRelativeUrl = sPFile.ServerRelativeUrl;
            string scriptLiteralToEncode = (serverRelativeUrl.IndexOf(".", StringComparison.Ordinal) > 0) ? SPUtility.MapToIcon(base.Web, serverRelativeUrl, string.Empty, IconSize.Size16) : "icgen.gif";
            string strScript = string.Format(CultureInfo.InvariantCulture, "retVal = {{}};\r\n                                            retVal['newFileUrl'] = \"{0}\";\r\n                                            retVal['isFolder'] = \"false\";\r\n                                            retVal['newFileSize'] = {1};\r\n                                            retVal['newFileIcon'] = \"{2}\";\r\n                                            window.frameElement.commitPopup(retVal);", new object[]
            {
                SPHttpUtility.EcmaScriptStringLiteralEncode(serverRelativeUrl),
                sPFile.Length,
                SPHttpUtility.EcmaScriptStringLiteralEncode(scriptLiteralToEncode)
            });
            sPLongOperation.EndScript(strScript);
        }
    }
    else
    {
        sPLongOperation.End(this.RedirectUrl, SPRedirectFlags.Static | SPRedirectFlags.UseSource, this.Context, null);
    }
}
else
{
    sPLongOperation.End(this.GetEditFormUrl(sPFile), SPRedirectFlags.Default, this.Context, null, base.IsDialogMode ? "window.frameElement.overrideDialogResult(1 /*ok*/);" : null);
}
  • I've double checked; the URL is right. I do have required attributes, so after Upload.aspx, the user gets redirected to EditForm.aspx to fill in the required metadata. Now I'm noticing it's when you hit EditForm.aspx that Source gets modified. I don't know where it's getting it from but Source becomes the URL of the list itself, and my Source gets lost. How could that be prevented while maintaining required attributes? – FrobberOfBits Mar 19 '15 at 16:40
  • You might be out of luck by requiring certain columns. Looking at the code posted above, it shows that if columns are required, it's going to redirect to the editform. This is where you are losing your source. If you are ALWAYS going back to the wiki after uploading a file to this library, then you might could do some JS magic on the editform.aspx page and add the querystring with the source in it so when they hit save it will redirect them back to the wiki page. You could also check the referrer to make sure it's coming from upload.aspx before you do this if needed. – Steve Lineberry Mar 19 '15 at 18:57
  • Well, this appears to be the answer, so I'm marking as accepted. I appreciate the help, and yet -- the answer is unfortunate. Requiring columns doesn't seem to have anything even remotely to do with where you should go after uploading a document, so that's disappointing. – FrobberOfBits Mar 19 '15 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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