Front End User upload to Document Library

Posted by Community Admin on 04-Aug-2018 22:05

Front End User upload to Document Library

All Replies

Posted by Community Admin on 12-Nov-2012 00:00

I need a way to allow anonymous front end users to upload documents to a specific document library. Is this possible?

Thanks,

Posted by Community Admin on 13-Nov-2012 00:00

Hi,

yes it's possible.

You can use this Telerik component (demos.telerik.com/.../defaultcs.aspx) and save the document in a specific targeted library.

Or create document from stream and register it to a library.
___________________________________________________________________________
Document docToAttach = null;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("Url");
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

using (Stream docStream = response.GetResponseStream())

     Stream customStream = new MemoryStream();
     docStream.CopyTo(customStream);

     docToAttach = LibrariesManager.GetManager().CreateDocument();
     docToAttach.Parent = null; //set My Library (DocumentLibrary)

     if (docToAttach.Parent == null)
   
           docStream.Close();
           customStream.Close();
           continue;
   

    docToAttach.Title = new Lstring("TEST");
...
    docToAttach.ApprovalWorkflowState.SetString(toAttach.Lang, "Published");
    LibrariesManager.GetManager().Upload(docToAttach, customStream, toAttach.Extension);

    docStream.Close();
    customStream.Close();

_______________________________________________________________________________

Regards,
Nicolas

Posted by Community Admin on 13-Nov-2012 00:00

Thank you Nicolas. I've modified the code to work in my situation and it runs without errors. However I never see the document in the specified library.

While debugging, I can see that most of the properties look correct, however the FilePath property is incorrect. It shows the library name followed by the extension and does not show the file name.

my-library-name/.doc

I've enumerated other files in the library and their FilePath look correct.
my-library-name/filename.doc

I've set the Title and can see that it is valid.
I can also see that the Uploaded property is True after executing line 20 below. I think its getting uploaded, but without the file name, the interface won't display the document.

Any ideas?

Thank you!

Here's the code that's running:
_______________________________________________________________________________

01.using (Stream docStream = ResumeUploadFU.FileContent)
02.        
03.            Stream customStream = new MemoryStream();
04.            docStream.CopyTo(customStream);
05. 
06.            docToAttach = LibrariesManager.GetManager().CreateDocument();
07.            DocumentLibrary resumesLibrary = LibrariesManager.GetManager().GetDocumentLibrary(Guid.Parse(DocumentLibraryGUID));
08.            docToAttach.Parent = resumesLibrary;
09. 
10.            if (docToAttach.Parent == null)
11.            
12.                docStream.Close();
13.                customStream.Close();
14.            
15. 
16.            docToAttach.Title = ResumeUploadPostBackTB.Text.Replace(" ", "");
17.            docToAttach.Extension = ResumeUploadFU.FileName.Substring(ResumeUploadFU.FileName.IndexOf("."));
18.            docToAttach.ApprovalWorkflowState.SetString("Published", true);
19.            LibrariesManager manager = LibrariesManager.GetManager();
20.            manager.Upload(docToAttach, customStream, docToAttach.Extension);
21. 
22.            docStream.Close();
23.            customStream.Close();
24.        

Posted by Community Admin on 14-Nov-2012 00:00

Hi,

You may have problem on Title because it's a Lstring type, give it a try : new Lstring(ResumeUploadPostBackTB.Text.Replace(" ", ""));

If you are in multilingual site you have to specify culture new Lstring(String, CultureInfo).

You have to set docToAttach.UrlName too.

Regards,
Nicolas

This thread is closed