This is a migrated thread and some comments may be shown as answers.

RadUpload for Moss 2007

13 Answers 224 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Rana Pratap
Top achievements
Rank 1
Rana Pratap asked on 12 Oct 2009, 04:02 AM
Hi ,

I want use RadUpload control for uploading files to sharepoint document library but i cant reference microsoft.sharepoint.dll into silverlight application . can you suggest me the best way to do this.

Thanks in advance
Regards,
Rana Pratap

13 Answers, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 12 Oct 2009, 06:51 AM
Hello Rana,

Thank you for your interest in the RadUpload for Silverlight.

The way to accomplish your task is to write a custom upload handler and inside it to populate the Sharepoint's database (instead of writing the uploaded file to the file system). Below are "how-to" instructions:
  • Write a common upload application - nothing special here;
  • Create a custom upload handler. link-1 and link-2;
    • Reference microsoft.sharepoint.dll;
    • Override the ProcessStream method;
    • Use the ChunkTag mechanism;
    • Save the uploaded data in Sharepoint instead in a local file.
Please follow the RadUpload ChunkTag or how to deal with uploaded files by chunk example, it is similar to your case (except Sharepoint related stuff).

More articles about RadUpload for Silverlight you can find in our online knowledge base repository.

We hope this information will help you.

Greetings,
Ivan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jimmy Jou
Top achievements
Rank 1
answered on 29 Nov 2009, 07:54 PM
Is there an API I can call to get the chunk of data so that they can be saved to SharePoint incrementally without saving to a local file sytem?
0
Valentin.Stoychev
Telerik team
answered on 02 Dec 2009, 07:12 AM
Hi Jimmy Jou,

You can modify the upload handler and implement your custom logic there:
http://www.telerik.com/help/silverlight/creating_custom_server-side_handler.html

Regards,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jimmy Jou
Top achievements
Rank 1
answered on 02 Dec 2009, 02:59 PM
That's exactly the question I am asking: how to get hold of the file stream if I don't want to save it to a file first. In another words, how can I get the file stream is a byte[] form?

The link says: Insert here your custom logic for processing the file stream

Jimmy
0
Ivan
Telerik team
answered on 07 Dec 2009, 09:35 AM
Hello Jimmy,

Thank you for contacting us.

Actually there are two main points you should be aware when you customize your upload-handler.
  1. Initializing the Chunk-Tag in order to track your files. Please note the ChunkTag is of type String. There are two places you can embed the initialization code in depending on the approach you prefer in step-2:
     
    public override void ProcessStream()
    {
        string chunkTag = this.FormChunkTag;
        if (this.IsNewFileRequest())
        {
            // Generate a new ChunkTag in order to tag all chunks.
            chunkTag = MyUniqueKeyGenerator.GetKey.ToString();
        }
        this.ResultChunkTag = chunkTag;
        ...

    or:
     
    public override bool InitializeChunkStorage(string filePath)
    {
        if (this.IsNewFileRequest())
        {
            this.ResultChunkTag = MyUniqueKeyGenerator.GetKey();
        }
        else if (this.FormChunkTag != null)
        {
            this.ResultChunkTag = this.FormChunkTag;
        }
        ...
     
    In your code you will use the Chunk-Tag value to save all chunks in one place.
     
  2. Save the uploaded data. Here you have two options:
    • Override the InitializeChunkStorage and the SaveChunkData methods. This is the easiest approach.
    • Rip and modify all the original ProcessStream method. This is more difficult approach as you should care about all internal return-parameters.

In the attached archive you can find a project-skeleton that implements the overriding of the InitializeChunkStorage and the SaveChunkData methods. Please note nothing is saved at the server-side - You should add your custom code in order to save the uploaded content - the original code is still inside these methods but commented.

Please give it a try and let us know if you need further assistance.

Kind regards,
Ivan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Laks
Top achievements
Rank 1
answered on 07 Mar 2010, 04:42 PM
Hello There,

I am trying to use the same example to upload a document in to the sharepoint document library.

I am not able to include the web dll into the bin folder. Whenever I include the dll with this implementation, my sharepoint application breaks and it doesnt allow the rad handler to be over ridden.

I am trying to use the follwing code for the SAVECHUNKDATA method

public override bool SaveChunkData(string filePath, long position, byte[] buffer, out long savedBytes) 
        { 
            bool success = false
            savedBytes = 0; 
            try 
            { 
                UploadFile1(buffer, "http://myserver/toolkit/ManagementDocuments/Forms/" + this.GetFileName()); 
                // Place your Save-in-DB code here. 
                savedBytes = buffer.Length; 
 
                // Note: do not forget to set the success value: 
                success = true
            } 
            catch (Exception e) 
            { 
                throw new Exception(e.Message); 
            } 
 
            if (!success) 
            { 
                string fileName = this.GetFileName(); 
                this.AddReturnParam(RadUploadConstants.ParamNameMessage, String.Format("Cannot save the file: [{0}]", fileName)); 
            } 
            return success; 

Please suggest a way to rectiy this.

Regards,
Laks






0
Ivan
Telerik team
answered on 08 Mar 2010, 12:34 PM
Hello Laks,

Thank you for contacting us.

We are not sure why the moss-application rejects the upload dll. Please note you should reference the Telerik.Windows.RadUploadHandler.dll file (the upload handler library). Are there some special permissions that prevent referencing of our library?

About the code inside the SaveChunkData - it looks pretty good. However I would like to point the call of the UploadFile1 method. Are you sure about it? Could you try to comment it in order to check the handler's behavior.

Looking forward for your reply.

Kind regards,
Ivan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Laks
Top achievements
Rank 1
answered on 08 Mar 2010, 06:02 PM
Here is the complete code. I have tried deplying the dll after removing the save method, it worked. Please let me know if you find anything

        public override bool SaveChunkData(string filePath, long position, byte[] buffer, out long savedBytes) 
        { 
            bool success = false
            savedBytes = 0
            try 
            { 
                UploadFile1(buffer, "http://myserver/toolkit/Management%20Documents/Forms/" + this.GetFileName()); 
                // Place your Save-in-DB code here. 
                savedBytes = buffer.Length; 
 
                // Note: do not forget to set the success value: 
                success = true
            } 
            catch (Exception e) 
            { 
                throw new Exception(e.Message); 
            } 
 
            if (!success) 
            { 
                string fileName = this.GetFileName(); 
                this.AddReturnParam(RadUploadConstants.ParamNameMessage, String.Format("Cannot save the file: [{0}]", fileName)); 
            } 
            return success; 
 
 
public void UploadFile1(byte[] contents, string destUrl) 
    SPWeb site = new SPSite(destUrl).OpenWeb(); 
    site.Files.Add(destUrl, contents); 

Thanks
0
Ivan
Telerik team
answered on 11 Mar 2010, 03:11 PM
Hello Laks,
 
Thank you for the sample code.
 
Now I've figure the issue out - in your sharepoint-related code you add a new file for each uploaded chunk. But the method you are relying on returns an error if the file already exists. Even more all the SPFileCollection.Add methods cannot append a piece of data - they always treat the supplied data as the whole file's content. Because of this you have two options:
 
  • If you depend on the SP's original API you should save the uploaded file to the file system first, and after the final file-request to save the file into SP.
  • If you still prefer to avoid the intermediate save to the file system, you should rely on a third party library.
 
We hope this information will help you.
 
Best wishes,
Ivan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Laks
Top achievements
Rank 1
answered on 23 Mar 2010, 10:30 AM
Thanks for your help
0
IT Support
Top achievements
Rank 1
answered on 02 Apr 2010, 09:09 PM
note that the way you are adding the file by opening the SPSite and SPWeb this way leads to memory leak.

Be sure to dispose them after use.

using(SPSite oSPsite = new SPSite(destUrl))
{
  using(SPWeb oSPWeb = oSPSite.OpenWeb())
   {
       
} }


0
ramireddy
Top achievements
Rank 1
answered on 31 Aug 2011, 05:37 PM
HI,
I am developing application using silverlight 4 but I need to upload my documents to Sharepoint 2010. Can I use the procedure as above,
is there any other way to do it.
Please let me know...........I using the same RadUpload Control for it.

Thanks
Ram
0
Tina Stancheva
Telerik team
answered on 05 Sep 2011, 02:37 PM
Hi Ram,

You can follow this tutorial http://tv.telerik.com/watch/silverlight/video/telerik-silverlight-controls-and-sharepoint-2010-part-5 as it will get you on the right track.

I also attached a sample project where the approach described in the video tutorial is used. Please, note that the UploadHandler implementation in the attached solution is different from the one demonstrated in the video tutorial. This is due to the improvements in the RadUpload control and it is best to use the UploadHandler implementation from the attached solution.

I hope this information will help you. However, if we can further assist you, please let us know.

Greetings,
Tina Stancheva
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Upload
Asked by
Rana Pratap
Top achievements
Rank 1
Answers by
Ivan
Telerik team
Jimmy Jou
Top achievements
Rank 1
Valentin.Stoychev
Telerik team
Laks
Top achievements
Rank 1
IT Support
Top achievements
Rank 1
ramireddy
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or