1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Upload Control for Document Library

Upload Control for Document Library

4 posts, 0 answered
  1. Chris Schrader
    Chris Schrader avatar
    14 posts
    Registered:
    19 Feb 2010
    21 Jul 2010
    Link to this post
    Is there a way for end users to upload files to a document library module? I don't want to grant the users access to the sitefinity/admin area and have them add documents there.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    21 Jul 2010
    Link to this post
    Hello Chris Schrader,

    3.x or  4.0? This thread is for 4.0 edition, so files uploading will be provided after the BETA.

    Kind regards,
    Ivan Dimitrov
    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
  3. Chris Schrader
    Chris Schrader avatar
    14 posts
    Registered:
    19 Feb 2010
    21 Jul 2010
    Link to this post
    I am using v3.7 sp3
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    21 Jul 2010
    Link to this post
    Hello Chris Schrader,

    You can create a public control  - RadUpload that uses Libraries API

    sample code (that uses streaming)

    public virtual  void ProcessUploading()
     {
        foreach(Telerik.Web.UI.UploadedFile file in  RadUpload1.UploadedFiles)
         {
                 Manager = new LibraryManager("Libraries");
             var fileStream = file.InputStream;
             var fileName = file.GetName();
             var ext = file.GetExtension();
             var mimeType = file.ContentType;
             ILibrary lib = Manager.GetLibrary("someLibrary");
      
      
             // CALL UploadFileFromStream
                 UploadFileFromStream(fileStream, fileName, ext, mimeType, lib, true);
         }
     }
      
      
     // CREATE A CUSTOM METHOD WHERE YOU PASS THE PARAMETERS FROM THE UPLOADED FILE. THE METHOD WILL HANDLE FILE UPLOADING AND SETTING THE METAKEYS
     public IContent UploadFileFromStream(Stream data, string fileName, string fileExtension, string mimeType, ILibrary library, bool overwrite)
     {
           Manager = new LibraryManager("Libraries");
         ILibrary selectedLibrary = library;
      
         if (overwrite)
         {
             MetaSearchInfo info = new MetaSearchInfo(MetaValueTypes.ShortText, "Name", fileName, SearchCondition.Equal, JoinType.And);
             MetaSearchInfo info2 = new MetaSearchInfo(MetaValueTypes.ShortText, "Extension", fileName, SearchCondition.Equal, JoinType.And);
             IMetaSearchInfo[] filter = new IMetaSearchInfo[] { info, info2 };
             Guid[] parentIDs = new Guid[] { selectedLibrary.ID };
             IList items = Manager.GetContent(0, 0, filter, parentIDs);
             if (items.Count > 0)
             {
                 IContent item = (IContent)items[0];
                 Manager.DeleteContent(item);
             }
         }
      
         IContent currentItem = Manager.CreateContent(mimeType);
         currentItem.ParentID = selectedLibrary.ID;
         if (!fileExtension.StartsWith("."))
             fileExtension = "." + fileExtension;
         currentItem.SetMetaData("Extension", fileExtension.ToLower());
         currentItem.SetMetaData("Size", data.Length);
         string newFileName = fileName;
         currentItem.SetMetaData("Name", newFileName);
      
         Manager.SaveContent(currentItem);
      
         currentItem = Manager.GetContent(currentItem.ID);
      
         // CHECK WHETHER THE STREAMING PROVIDER IS ENABLED OR NOT
         if (Manager.Provider.StreamingProvider == null)
         {
             currentItem.Content = StreamHelper.ReadToEnd(data, true);
         }
         else
         {
             // THE APPLICATION IS USING THE STREAMING PROIVIDER
             using (var uploadStream = Manager.Provider.StreamingProvider.GetUploadStream((IStreamableContent)currentItem))
             {
                 StreamHelper.CopyStream(data, uploadStream, true, Manager.Provider);
             }
         }
         Manager.SaveContent(currentItem);
         // PROCEED WITH OTHER TASKS...
         // currentItem = Manager.GetContent(currentItem.ID);
         return currentItem;
     }
      
     private LibraryManager Manager;




    Kind regards,
    Ivan Dimitrov
    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
4 posts, 0 answered