Front End User upload to Document Library
I need a way to allow anonymous front end users to upload documents to a specific document library. Is this possible?
Thanks,
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
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
my-library-name/filename.doc
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.
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