I always thought that only file in the document library would support online editing. Until this morning I found that using IE to open the list inside the attachments is also supported online editing, but only if it must be IE browser.
Currently under development of the project, I began to design is to put all the approval information stored in the list, uploaded documents in the form of attachments in the list, yesterday, the customer came to the company, I demonstrated the time, with the chrome open attachment, directly downloaded (later recommended using IE), Customers need online editing functions, but also mercilessly granted us a meal, attachments can not be online editing, then I audit a yarn. (In fact, it can be, with IE on the line.) After the end, I did not think much (inexperienced) directly to the code, the FileUpload uploaded files saved to a document Library log, in fact, this is completely redundant.
If you want to edit the uploaded document online in SharePoint, there are 2 ways to upload it, of course, upload it to the document library, and one of these is uploading to the list with attachments.
List
First, the update operation is performed on the ListItem.
if (fileattachment.hasfile)
{
try
{
foreach (var file in fileattachment.postedfiles)
{
NEWITEM.ATTACHMENTS.ADD (file. FileName, file. Inputstream.readfully ());
}
catch ()
{
}
}
newitem.update ();
Then the list of ListItem edit WebPart, using hyperlink to draw the attachment, in fact, to get the URL address of the attachment
SPListItem NewItem = This._applyitemlist.getitembyid (this. OBJECTID);
HyperLink Hyperlink=null;
foreach (String currentattachment in newitem.attachments)
{
hyperlink=new hyperLink ();
Hyperlink.id = Guid.NewGuid (). ToString ();
String attachmentabsoluteurl = NewItem.Attachments.UrlPrefix + currentattachment;
SPFile attachmentfile = This._currentweb.getfile (attachmentabsoluteurl);
Hyperlink.text = Attachmentfile.name;
Hyperlink.navigateurl = Attachmentabsoluteurl;
PHATTACHMENT.CONTROLS.ADD (hyperLink);
Add newline
phAttachment.Controls.Add (New LiteralControl ("<br />"));
Finally in the edited WebPart as shown below, directly with IE open, support online editing, but no history
Of course, you can upload the document to the document library, upload it to the document library, and your operation has a history.
Document Library
For example, I will fileupload uploaded files to the appropriate folder in the document library, to listid+ "-" +listitemid named folder, so as to avoid uploading documents with the same name, first of all to determine whether there is this folder, does not exist to create, when the creation is completed, Place the document in the document library under this folder:
if (fileattachment.hasfile) {try {foreach (var file in
Fileattachment.postedfiles) {using (SPSite Logsite = SPContext.Current.Site)
{using (SPWeb Logweb = logsite.allwebs["Log")
{logweb.allowunsafeupdates = true;
Spdocumentlibrary Library = logweb.lists["Approveattachmentlog"] as spdocumentlibrary; String rooturl = library.
Rootfolder.url;
String listid = _applyitemlist.id.tostring ();
String listitemid = NewItem.ID.ToString ();
String FolderUrl = Rooturl + "/" + listid+ "-" + listitemid;
SPFolder folder = Logweb.getfolder (FolderUrl); if (!folder. Exists) {SPListItem NewFolder = library. Folders.Add (library.
Rootfolder.serverrelativeurl, Spfilesystemobjecttype.folder, Listid + "-" + listitemid);
Newfolder.update (); Stream stream = file.
InputStream; byte[] Bytfile = new Byte[convert.toint32 (file.
ContentLength)]; Stream. Read (bytfile, 0, Convert.ToInt32) (file.
ContentLength)); Folder. Files.add (System.IO.Path.GetFileName) (file.
FileName), Bytfile, true);
Logweb.allowunsafeupdates = false;
}
}
}
} catch (Exception) {}}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/web/sharepoint/