The following example steps through the process of adding an UploadCtl control to an .aspx page for uploading multiple documents to the Shared Documents folder of a specified site. The example adds a hidden UploadCtl control within the page that is displayed when a link is clicked.
The .aspx file, in this example WebForm1.aspx, must be located in the Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS directory, and is opened through the URL http://Server_Name/_layouts/WebForm1.aspx.
-
Add a page directive that registers the Microsoft.SharePoint.WebControls namespace:
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
-
Add a LINK element in the HEAD section to apply Windows SharePoint Services styles that are defined in ows.css:
<LINK REL="stylesheet" TYPE="text/css" HREF="/_layouts/1033/styles/ows.css">
-
Add a script block to the HEAD section that includes two methods. One method sets the background color for the tree view and displays the UploadCtl on the page. The other method uploads documents that are selected in the control.
<SCRIPT LANGUAGE="javascript"> function MultipleUploadView() { document.all.idUploadCtl.SetTreeViewColor("#FF0000"); document.all("idMultipleView").style.display="inline"; } function DocumentUpload() { document.all.idUploadCtl.MultipleUpload(); } </SCRIPT>
-
Add a form within the BODY section of the .aspx page:
<FORM NAME="frmUpload" METHOD="post"
ACTION="WebForm1.aspx?RootFolder=& Source=
http%3A%2F%2FServer_Name%2FShared%2520Documents
%2FForms%2FAllItems%2Easpx"> -
To upload documents and thereby modify data within a SharePoint site, you must include a FormDigest server control in the form:
<SharePoint:FormDigest runat="server" /> -
Include INPUT elements that specify the required parameters of the post:
<INPUT TYPE="hidden" NAME="Cmd" VALUE="Save"> <INPUT TYPE="hidden" NAME="NextUsing" VALUE="http://Server_Name/ Shared%20Documents/Forms/AllItems.aspx"> <INPUT TYPE="hidden" VALUE="New"> <INPUT TYPE="hidden" NAME="putopts" VALUE="true"> <INPUT TYPE="hidden" NAME="destination" VALUE="http://Server_Name/Shared Documents"> <INPUT TYPE="hidden" NAME="Confirmation-URL" VALUE="http://Server_Name/Shared%20Documents/ Forms/AllItems.aspx"> <INPUT TYPE="hidden" NAME="PostURL" VALUE="http%3a%2f%2fServer_Name/_vti_bin/ shtml.dll/_layouts%2fWebForm1%2easpx" /> <INPUT TYPE="hidden" NAME="VTI-GROUP" VALUE="0">
-
To complete the form, add a link for calling the MultipleUploadView method and displaying the contents of a DIV section, which includes the <OBJECT> tag that creates the control on the page: