0

I have a SharePoint 2010 environment that has a SSRS report. The user clicks a button and sees the report rendered via PDF. I would like to instead of downloading that PDF, place it into a document library. Is this possible via JavaScript and web services?

1
  • 2
    It is possible on the SSRS side to schedule the report and deliver it to a document library, not quite the same as how you want it, but if it is a weekly type report, you can always automate it for users Jan 30, 2015 at 14:20

2 Answers 2

0

Nathan,

If you are using code behind, you can write a function to upload the generated file (must be saved to your server hard drive first) to your document library.

Here I'm calling my UploadFile function and sending it the source file destination and library destination.

UploadFile("C:\Templates\" + Num.Trim() + ".docx", "https://mysite/libraryname/" + employer + "_" + Num.Trim() + ".docx");

    private void UploadFile(string srcUrl, string destUrl)
    {
        if (!File.Exists(srcUrl))
        {
            throw new ArgumentException(String.Format("{0} does not exist", srcUrl), "srcUrl");
        }

        SPWeb site = new SPSite(destUrl).OpenWeb();
        site.AllowUnsafeUpdates = true;
        FileStream fStream = File.OpenRead(srcUrl);
        byte[] contents = new byte[fStream.Length];
        fStream.Read(contents, 0, (int)fStream.Length);
        fStream.Close();

        EnsureParentFolder(site, destUrl);
        site.Files.Add(destUrl, contents, true);
    }

    private string EnsureParentFolder(SPWeb parentSite, string destinUrl)
    {
        destinUrl = parentSite.GetFile(destinUrl).Url;

        int index = destinUrl.LastIndexOf("/");
        string parentFolderUrl = string.Empty;

        if (index > -1)
        {
            parentFolderUrl = destinUrl.Substring(0, index);

            SPFolder parentFolder
                = parentSite.GetFolder(parentFolderUrl);

            if (!parentFolder.Exists)
            {
                SPFolder currentFolder = parentSite.RootFolder;

                foreach (string folder in parentFolderUrl.Split('/'))
                {
                    currentFolder
                        = currentFolder.SubFolders.Add(folder);
                }
            }
        }
        return parentFolderUrl;
    }
0

You can create an ISAPI web service, call the endpoint using jQuery AJAX and utilize server side code to upload to the proper location.

ISAPI Service https://msdn.microsoft.com/en-us/library/office/ms464040%28v=office.14%29.aspx

Upload file SSOM https://stackoverflow.com/questions/468469/how-do-you-upload-a-file-to-a-document-library-in-sharepoint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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