RadUpload in SharePoint Sandbox environment

9 posts, 0 answers
  1. Pinaki
    Pinaki avatar
    10 posts
    Member since:
    Nov 2010

    Posted 27 Feb 2012 Link to this post

    Hello Readers.I'm starting a new thread here, since I could not find an answer to my problem anywhere else.

    Typically me scenrio is that I want to use the RadUpload and the RandUploadHandler in SharePoint but in a Sandbox solution.
    So, although you can create modules, you can't create and use the layouts folder.

    Can someone help me with can example of where the uploadhandler.ashx should be, where should the codebehind Uploadhandler.cs go, and what is the correct URL sytanx to use for the UploadServiceURL property?

    Any help or guideance on this will be appreciated.

    Thank you.

  2. Pinaki
    Pinaki avatar
    10 posts
    Member since:
    Nov 2010

    Posted 01 Mar 2012 Link to this post

    Anyone? Telerik?
    Question is simple. Is is possible to implement your RadUplaod example (aslo seen the video) in a sandbox solution. My question is where to put the uploadhandler ashx and code?
  3. DevCraft banner
  4. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 01 Mar 2012 Link to this post

    Hi Pinaki,

    Please accept our apology for the delayed response.

    In a SharePoint solution there are many restrictions which you'll need to work around in order to upload files using the RadUpload control.

    Firstly, you'll need to upload the RadUploadHanler somewhere on your server where the RadUpload can access it. However, by default in SharePoint the .ashx files are blocked and you'll need to change that by removing this type of files from the blocked file types list. This will allow you to upload the UploadHandler in a library in SharePoint or add it in a Module in the SharePoint solution.

    But the UploadHandler.ashx file needs a code-behind file and you'll need to make sure that the Telerik.Windows.RadUploadHandler.dll can be accessed and found by the server. For example you can add the following UploadHandler in the SilverlightXAP module (from the video tutorial)
    <%@ WebHandler Language="C#" Class="UploadProject.UploadHandler" %>
    <%@ Assembly Name="Telerik.Windows.RadUploadHandler" %>
    using Telerik.Windows;
    using System.IO;
     
    namespace UploadProject
    {
        public class UploadHandler : RadUploadHandler
        {
        }
    }
    And make sure that the Telerik.Windows.RadUploadHandler.dll is included into the SharePoint project Package.

    When you add the SampleUploadHandler to the SilverlightXAP module, you can access it under the following path: /SilverlightXAP/SampleUploadHandler.ashx, and this should be the value of the RadUpload.UploadServiceUrl property.

    Also you need to keep in mind that the RadUpload control logic needs access to its TargetFolder in order to save the selected files.

    Basically when you create a Sandbox solution which takes advantage of the RadUpload control, you need to carefully plan your server configuration, the Sandbox solution permissions and deployment strategy so that the client-side can access the UploadHandler file as well as the directory where the files will be stored.

    All the best,
    Tina Stancheva
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  5. Pinaki
    Pinaki avatar
    10 posts
    Member since:
    Nov 2010

    Posted 04 Mar 2012 Link to this post

    Hi Tina.
    Thank you for your tips, but it still does not help.
    Let me explain what's going on.
    Unlike other examples given, mine needs to be a sandbox solution, and so can't use _layouts. So, I've done exactly as you had mentioned above. My .ashx file now has code inside it, (not a code behind). My uploadhandler ashx file (a single file now) looks like this.

    <%@ WebHandler Language="C#" Class="SandBoxFileUpload.UploadHandler,SandBoxFileUpload, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3ebdc90910e74959" %>
    <%@ Assembly Name="Telerik.Windows.RadUploadHandler" %>
     
    using System;
    using System.IO;
    using Microsoft.SharePoint;
    using Telerik.Windows;
     
    namespace SandBoxFileUpload
    {
        public class UploadHandler : RadUploadHandler
        {
            public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)
            {
                bool result = base.SaveChunkData(filePath, position, buffer, contentLength, out savedBytes);
                if (IsFinalFileRequest())
                {
                    SPContext.Current.Web.AllowUnsafeUpdates = true;
                    var fStream = new FileStream(filePath, FileMode.Open);
                   //.....
                }
             }
    }



    But the problem is, at runtime, it can't find the Telerik.Windows.RadUploadHandler DLL even though it is included in my package, to be deployed.


    My manifest has the dll included, and I still get the error. See attached screenshot.

    I've spent too much time on it, and really need some help here. Can Telerik help?

    Thank you.

  6. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 05 Mar 2012 Link to this post

    Hello Pinaki,

    When you add the Assembly tag with the Name property, the handler will be looking for the targeted assembly in the GAC. Basically in this case it doesn't use the assembly from the package but it needs to find it in the GAC, so can you please make sure that the Telerik.Windows.RadUploadHandler.dll is in the GAC?

    Let me know how it goes.

    Kind regards,
    Tina Stancheva
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  7. Pinaki
    Pinaki avatar
    10 posts
    Member since:
    Nov 2010

    Posted 13 Mar 2012 Link to this post

    Hi Tina. and all at Telerik.
    Thank you for your help so far, but I've still not come to a solution. I've implemented all the tips you all have mention here, till the last step.

    But my situation is:
    This all works fine if the the RadUploadHandler  DLL is in the GAC, and the Uploadhandler.ashx file (code in the file, and no .cs file) then it works fine.
    But since I need to deploy this in a sandbox solution  that is very much closed environment, I cannot access  the GAC. So, I need a way to make this work without adding the DLL to the GAC.

    I've already included the DLL as a part of the SharePoint package and have added the entry Package Manifest.

    My Uploadhandler looks something like this:
    <%@ Assembly Name="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Assembly Name="Telerik.Windows.RadUploadHandler, Version=2012.1.215.40, Culture=neutral, PublicKeyToken=5803cfa389c90ce7" %>
    <%@ WebHandler Language="C#" Class="SandboxFileUpload.UploadHandler" %>
    using System;
    using Telerik.Windows;
    using Microsoft.SharePoint;
    using System.IO;
     
    namespace SandboxFileUpload
    {
        public class UploadHandler : RadUploadHandler
        {
     
           public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength,
                                               out int savedBytes)
            {
                bool result = base.SaveChunkData(filePath, position, buffer, contentLength, out savedBytes);
                // ....
             }
    }
    }

    Now is there anyway to make the handler work without  the DLL in the GAC?.
    Can we make a code behind .cs file for this handler using the normal " using..." clause?

    The .ashx is inside a module in my solution like SilverlightXAP.
    Where should the .cs file be? On the Sharepoint solution root level?

    Please help me solve this, Tina.
    Your help is appreciated.

    Thank you.

  8. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 16 Mar 2012 Link to this post

    Hi Pinaki,

    Unfortunately I am not aware of other approaches other than placing the code-behind code in the ashx file and the Telerik.Windows.UploadHandler assembly in GAC.

    Kind regards,
    Tina Stancheva
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  9. Pinaki
    Pinaki avatar
    6 posts
    Member since:
    May 2012

    Posted 01 Jun 2012 Link to this post

    Hello all at Telerik.
    I still have not found a good working solution on this topic.
    Basically I need a solution for the UploadHandler.ashx to work without putting any DLL on GAC. Since I'm working in a SandBox solution, I can't access the GAC.

    I've already tried the following steps:

    1. Telerik.Windows.RadUploadHandler.DLL added to manifest, with a <SafeControl>. It did not work.
    2. compiled the code of the DLL making my own DLL, signed, and added it to the WSP. It did not work.
    3. Tried with the uploadhandler.ashx with code  besides. It did not work.
    4. Tried it with code behind .CS file. It did not work.

    The project only works with you put the DLL in GAC. This is a no-go for Sandbox solutions in SharePoint 2010.

    Any help please?

    Thank you.

  10. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 06 Jun 2012 Link to this post

    Hello Pinaki,

    Due to the Sandbox environment limitations, it is very hard to use in the solutions any dynamic controls that rely on external resources. This is why the RadUpload control can't work in a Sandbox solution as its handler should derive from the RadUploadHandler class.

    My previous suggestions are the only workaround that we are aware of.

    Regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner