Document upload without going into the back end?
Does anyone know of method or module that will allow document upload and/or content editing in place without the user having to go into the backend?
i.e. I have an intranet and would like to allow pages in the HR section to be edited and maintained by HR personnel without having to let them into the back end. Does anyone know of a method or module that will allow this?
Hi John,
You can create custom widget where to use <asp:FileUpload> control. For example:
- Markup:
<
asp:FileUpload
id
=
"FileUpload1"
runat
=
"server"
>
</
asp:FileUpload
>
<
asp:Button
id
=
"UploadButton"
Text
=
"Upload file"
OnClick
=
"UploadButton_Click"
runat
=
"server"
>
</
asp:Button
>
protected
void
UploadButton_Click(
object
sender, EventArgs e)
if
(
this
.FileUpload1.HasFile)
LibrariesManager librariesManager = LibrariesManager.GetManager();
Document document = librariesManager.CreateDocument(Guid.NewGuid());
DocumentLibrary documentLibrary = librariesManager.GetDocumentLibraries().Where(d => d.Title ==
"Default Library"
).SingleOrDefault();
document.Parent = documentLibrary;
document.Title =
this
.FileUpload1.FileName;
document.DateCreated = DateTime.UtcNow;
document.PublicationDate = DateTime.UtcNow;
document.LastModified = DateTime.UtcNow;
document.UrlName = Regex.Replace(document.Title.ToLower(), @
"[^\w\-\!\$\'\(\)\=\@\d_]+"
,
"-"
);
//Recompiles and validates the url of the document.
librariesManager.RecompileAndValidateUrls(document);
string
path = Server.MapPath(
"~/"
);
//saves the file in your project folder
this
.FileUpload1.SaveAs(path + FileUpload1.FileName);
string
documentPath = Server.MapPath(
this
.FileUpload1.FileName);
FileStream fileStream =
new
FileStream(documentPath, FileMode.Open);
string
extension = Path.GetExtension(documentPath);
//Upload the document file.
librariesManager.Upload(document, fileStream, extension);
//Save the changes.
librariesManager.SaveChanges();
//Publish the DocumentLibraries item. The live version acquires new ID.
var bag =
new
Dictionary<
string
,
string
>();
bag.Add(
"ContentType"
,
typeof
(Document).FullName);
WorkflowManager.MessageWorkflow(document.Id,
typeof
(Document),
null
,
"Publish"
,
false
, bag);
How do I create that widget so that I can hand it off to my system admins to deploy to a production environment? is it built as a dll? or is there a way to package it for deployment? All of the videos and documentation shows that I deploy it thru visual studio but my VS does not have access to the production environment.
@John
You should create a new assembly project, add your widget(s) into that. Then you can just hand it off to your admins to plop in the "bin" folder, which will recycle the site.
You can follow this code sample to auto-add the widget(s) to your toolbox
www.sitefinity.com/.../creating-self-installing-widgets-and-modules-in-sitefinity
...or just do it manually when they tell you it's been added.
@Steve,
When you say a new assembly project are you talking just a plain old VS assembly project or some sort of special assembly project thru thunder or with Sitefinity templates?
TIA
Plain, Add->New Project->Class Library
Then in your SF project, reference that project, and in that project add references back to like Telerik.Sitefinity, Telerik.Sitefinity.Model, Telerik.Sitefinity.Utilities or whatever you might need.
If you have Sitefinity Thunder installed you can jsut right-click the Class Library (or a folder in it) and
Add->New Item->Sitefinity->Sitefinity Widget with Designer
build...new widget created...available to add to your toolbox and use right away!