Introduction: UploadCtl is an ActiveX control shipped with MSOffice 2003 which allows multiple documents to be uploaded from an external application to a document library on a site in Microsoft Windows SharePoint Services. So, in this way we can upload multiple files at a time in any Document Library. Now, the Question is can we use the same functionality in our custom pages. The answer is yes, we can use this feature. I have still unable to use this Active X control in ASP.Net application. But I have used it in SharePoint Application.
Solution: if we look at the URL of above Page(Image), it is like http://testserver/sites/SC1/S1/_layouts/Upload.aspx?List=%7BF47C2727%2DA464%2D4CA0%2DB2F7%2D7464E56522BD%7D&RootFolder=%2Fsites%2FSC1%2FS1%2FPages&Source=http%3A%2F%2Fteseserver%2Fsites%2FSC1%2FS1%2FPages%2FForms%2FAllItems%2Easpx&MultipleUpload=1
Upload.aspx page uses these following querystring to upload the file. If we decode it we find that
List= ListID Root Folder= /sites/SC1/S1/Pages Source= http://teseserver/sites/SC1/S1/Pages/Forms/AllItems.aspx //Redirect the page here after upload MultipleUpload=1 //It shows we need to open Multiple Upload Page
So, we can redirect the page with those above QueryStrings.
The Design Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>Multi Upload</title> </head> <body> <form id="form1" runat="server"> <object id="objMultiUpload" name="objMultiUpload" classid="CLSID:07B06095-5687-4d13-9E32-12B4259C9813" width="100%" ></object> <asp:Button ID="btnMultiFile" runat="server" Text="Upload all" OnClick="btnMultiFile_Click" /> <input type="hidden" name="Confirmation-URL" value="<%= _redirectURL %>" /> <input type="hidden" id="PostURL" name="PostURL" /> </form> </body> </html>
The CLSID:07B06095-5687-4d13-9E32-12B4259C9813 is the CID of the Upload ActiveX Control.
Coding Page:
The attachment process will go through two steps
if (Request.Files.Count > 0) { HttpPostedFile File = null; for (int i = 0; i < Request.Files.Count; i++) { File = Request.Files[i]; if (dtAttachFile == null) { AddMoreColumns(); } if (File != null && File.FileName != String.Empty && File.ContentLength > 0) { drAttachFile = dtAttachFile.NewRow(); string _tempFolder = Environment.GetEnvironmentVariable("TEMP"); string _fileTime = DateTime.Now.ToFileTime().ToString(); string _fileName = System.IO.Path.GetFileName(File.FileName); string _newfilePath = _fileTime + "~" + _fileName; string _filepath = _tempFolder + "\\" + _newfilePath; File.SaveAs(_filepath); drAttachFile["FileName"] = _fileName; drAttachFile["FilePath"] = _filepath; dtAttachFile.Rows.Add(drAttachFile); } } SPList List = this._myTeamSite.Lists[Request.QueryString["List"]]; SPListItem newItem = List.Items.Add(); foreach (DataRow drAttachFile in dtAttachFile.Rows) { fileName = drAttachFile["Filename"].ToString(); strFilepath = drAttachFile["FilePath"].ToString(); StreamReader sr = new StreamReader(strFilepath); Stream fStream = sr.BaseStream; contents = new byte[fStream.Length]; fStream.Read(contents, 0, (int)fStream.Length); fStream.Close(); newItem.Attachments.Add(fileName, contents); System.IO.File.Delete(strFilepath); } this._myTeamSite .AllowUnsafeUpdates = true; newItem.Update(); this._myTeamSite .AllowUnsafeUpdates = false; }
Download the source code:
http://cid-9f89234e32135c71.office.live.com/self.aspx/.Public/Multiple%20Upload%20Control%20in%20SP.zip Reference: http://msdn.microsoft.com/en-us/library/ms456628(v=office.12).aspx For multiple file upload you can look at: http://social.technet.microsoft.com/wiki/contents/articles/2947.aspx Jayant Sharma
Maheshkumar S Tiwari edited Original. Comment: Added tags
good one.
I am able to make it work in 2007...
But its not working with SharePoint 2010 (Office 2010 STSUPLD.dll) drag and drop control.
Please let me know if you have any soln.
Nice article!
I cannot get this to work in 2010 either
To control (Office 2010 STSUPLD.dll) to work properly with SharePoint 2010, add on page element
<input type="hidden" name="destination" id="destination" value="/Documents" />
where for value specify relative Document Library Url