More in this section

Forums / Developing with Sitefinity / Front End User upload to Document Library

Front End User upload to Document Library

4 posts, 0 answered
  1. Jeremy
    Jeremy avatar
    17 posts
    Registered:
    28 Jul 2010
    12 Nov 2012
    Link to this post
    I need a way to allow anonymous front end users to upload documents to a specific document library. Is this possible?

    Thanks,
  2. Nicolas
    Nicolas avatar
    156 posts
    Registered:
    19 Jan 2011
    13 Nov 2012
    Link to this post
    Hi,

    yes it's possible.

    You can use this Telerik component (http://demos.telerik.com/aspnet-ajax/asyncupload/examples/overview/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
  3. Jeremy
    Jeremy avatar
    17 posts
    Registered:
    28 Jul 2010
    13 Nov 2012 in reply to Nicolas
    Link to this post
    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.        }

  4. Nicolas
    Nicolas avatar
    156 posts
    Registered:
    19 Jan 2011
    14 Nov 2012
    Link to this post
    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
4 posts, 0 answered