Upload Control for Document Library
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.
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
I am using v3.7 sp3
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;