kamagra how much to take

Using Telerik RadUpload Control with SharePoint Document Libraries ASP.NET

The RadUpload control is probably my favorite control out of the Telerik suite. I really dig the progress indicators, and have used both the ASP.NET and Silverlight ports thoroughly in client applications. In this post I am going to show you how to use the ASP.NET control when you want to upload documents to a SharePoint document library. Since the Silverlight control requires a custom HTTP handler, the two approaches are going to be very different. However at the end of the day the end result will be through since I will also demonstrate how to push the requisite parameter based metadata ala a HashTable.

Firstly, let’s go through the easy one, the ASP.NET control. Next post, I will show you the Silverlight approach (which is more complex). In this example, I am going to scrap a Control for all the RadUpload controls by recurring through the available ControlCollections by Type, then get all the files specified within the upload control, and push em to a literally defined document library. Firstly, to get the controls by Type I am going to use the following static method:

  2. public static List<T> FindControlRecursiveByType<T>(Control root) where T : Control
  3. {
  4. List<T> res = new List<T>();
  5. if (root != null)
  6. {
  7. Stack<Control> tmpStack = new Stack<Control>();
  8. tmpStack.Push(root);
  9. while (tmpStack.Count > 0)
  10. {
  11. Control ctrl = tmpStack.Pop();
  12. if (ctrl is T)
  13. {
  14. res.Add(ctrl as T);
  15. }
  16. foreach (Control childCtrl in ctrl.Controls)
  17. {
  18. tmpStack.Push(childCtrl);
  19. }
  20. }
  21. }
  22. return res;
  23. }

This part is pretty straightforward. Next, I am going to use this method to expose the RadUpload controls, get the files, and push them to the appropriate document library. So that the method is more portable for the folks reading this post, I have put it in a copy-and-paste ready static format that is easy to integrate into your application.

  1. public static void IterateAllUploadControls(Control wiz, SPListItem item)
  2. {
  3. SPSecurity.RunWithElevatedPrivileges(delegate
  4. {
  5. List<RadUpload> x = FindControlRecursiveByType<RadUpload>(wiz);
  6. foreach (RadUpload upload in x)
  7. {
  8. foreach (UploadedFile file in upload.UploadedFiles)
  9. {
  10. SPSite initialSite = new SPSite(SharePointHelpers.SiteUrl);
  11. using (var site = new SPSite(SharePointHelpers.SiteUrl, initialSite.SystemAccount.UserToken))
  12. {
  13. {
  14. using (var web = site.OpenWeb())
  15. {
  16. SPDocumentLibrary library = (SPDocumentLibrary) web.Lists["Documents"];
  17. SPFolder folder = library.RootFolder;
  18. Hashtable metaData = new Hashtable
  19. {
  20. {
  21. Something, item["Something"].ToString()
  22. }
  23. };
  24. web.AllowUnsafeUpdates = true;
  25. folder.Files.Add(String.Format("{0}/{1}", folder.Url,file.FileName), file.InputStream,metaData, true);
  26. }
  27. }
  28. }
  29. }
  30. }
  31. });
  32. }

None of this is very fantastic. Basically, we are surfacing all the RadUpload controls on a Control, iterating through all the uploaded files, and adding them to the RootFolder of the SharePoint document library. Simple, yet effective. Next post I will show you how to accomplish the same thing in Silverlight. Which is not nearly as straightforward :)


No Comments


  1. Using Telerik RadUpload Control with SharePoint Document Libraries – Silverlight | ARB Security Solutions - [...] Posts Using Telerik RadUpload Control with SharePoint Document Libraries – SilverlightUsing Telerik RadUpload Control with SharePoint Document Libraries …

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>