html 这会将文件上传到SharePoint库,并使用javascript和jquery从网页添加元数据。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 这会将文件上传到SharePoint库,并使用javascript和jquery从网页添加元数据。相关的知识,希望对你有一定的参考价值。

<script type="text/javascript" src="https://xxxxx/Utilities/jquery-1.11.2.min.js"></script>
		</ContentTemplate>
	</SharePoint:UIVersionedContent>
	<script type="text/javascript">
$(document).ready(function() {
    var ups = getUrlVars()
    setValues(ups);
});

String.prototype.replaceAll = function (find, replace) {
    var str = this;
    return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
};

function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,    
    function(m,key,value) {
      vars[key] = value;
    });
    return vars;
}
function setValues(ups){
for(var index in ups)
{
	var key = index;
	var value = decodeURI(ups[index].replaceAll('%C3%82%C2%A0',' ').replaceAll('%3A',':'));//%C3%82%C2%A0
    
	//console.log(key + ": " + value);
    if(key.indexOf("fdx") > -1)
	{
		var titleValue = key.replace('fdx','').replaceAll('%C3%82%C2%A0','');
		var elements = document.querySelectorAll('[id="' + titleValue + '"]');// + titleValue + "']");
		var att = document.createAttribute("value");
		att.value = value;
		if(elements[0] != null)
			elements[0].setAttributeNode(att);			
		
	}
	//alert(key);
}//end for
}

function loadFile() {
     var filePath = $('#attafh').val(); // "c:\\test.pdf";
     var file = filePath.match(/\\([^\\]+)$/)[1];
     var siteValue = $('#Site').val();
     var UICValue = $('#UIC').val();
     var commandValue = $('#Command').val();
     var batchValue = $('#Batch').val();
     
     //var errorObj = $('#Error');
//     var selectedIndex = errorObj.selectedIndex;
	 var errorValue = $('#Error').val();// errorObj.options[selectedIndex].value;
	 
     var approvedValue = $('#Approved').val();
     var approvedDateValue = $('#ApprovedDate').val();

         var soapEnv =
             "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
                 <soap:Body>\
                     <CopyIntoItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>\
                         <SourceUrl>" + filePath + "</SourceUrl>\
                             <DestinationUrls>\
                                 <string>https://xxxxxx/" + file + "</string>\
                             </DestinationUrls>\
                             <Fields>\
                                 <FieldInformation Type='Text' DisplayName='UIC_Num' InternalName='UIC' Value='"+UICValue +"'  />\
								 <FieldInformation Type='Text' DisplayName='Site' InternalName='Site' Value='"+siteValue +"'  />\
 								 <FieldInformation Type='Text' DisplayName='Command' InternalName='Command' Value='"+commandValue+"'  />\
								 <FieldInformation Type='Text' DisplayName='Batch' InternalName='Batch' Value='"+batchValue+"'  />\
								 <FieldInformation Type='Text' DisplayName='Error' InternalName='Error' Value='"+errorValue+"'  />\
								 <FieldInformation Type='Text' DisplayName='Approved By' InternalName='Approved_x0020_By' Value='"+approvedValue+"'  />\
								 <FieldInformation Type='DateTime' DisplayName='Date Approved' InternalName='Date_x0020_Approved' Value='"+approvedDateValue+"'  />\
                             </Fields>\
                         <Stream>base64Binary</Stream>\
                     </CopyIntoItems>\
                 </soap:Body>\
             </soap:Envelope>";

         $.ajax({
             url: "https://xxxxxx/_vti_bin/copy.asmx",
             beforeSend: function (xhr) { xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems"); },
             type: "POST",
             dataType: "xml",
             data: soapEnv,
             error: errorHandler,
             success: processResult,
             contentType: "text/xml; charset=\"utf-8\""
         });

}

function errorHandler(evt) {
    alert(evt);
}
 
function processResult(evt) {
	alert('Success!!');
	window.location.href = 'https://xxxxxx/Forms/AllItems.aspx';
}
</script>

<table>
<tr>
<td>Site:</td><td><input id="Site"></input></td>
</tr>
<tr>
<td>UIC:</td><td><input id="UIC"></input></td>
</tr>
<tr>
<td>Command Name:</td><td><input id="Command"></input></td>
</tr>
<tr>
<td>Batch:</td><td><input id="Batch"></input></td>
</tr>
<tr>
<td>Error:</td>
<td>
<select id="Error">
  <option value="Laundered TLD">Laundered TLD</option>
  <option value="Damaged TLD">Damaged TLD</option>
  <option value="Lost TLD">Lost TLD</option>
  <option value="Flown TLD">Flown TLD</option>
  <option value="L2/L1">L2/L1</option>
  <option value="Greater than 100mrem">Greater than 100mrem</option>
  <option value="Unexpected Exposure">Unexpected Exposure</option>
  <option value="Shallow/Deep Discrepancy">Shallow/Deep Discrepancy</option>
  <option value="Improperly Stored Controls">Improperly Stored Controls</option>
  <option value="Control Value Discrepancy">Control Value Discrepancy</option>
  <option value="TLD Incorrectly Assigned">TLD Incorrectly Assigned</option>
  <option value="Other" selected="selected">Other</option></select>
</td>
</tr>
<tr>
<td>Approved By:</td><td><input id="Approved"></input></td>
</tr>
<tr>
<td>Date Approved:</td><td><input id="ApprovedDate"></input></td>
</tr>
</table>
<input id="attafh" type="file" class="AlltextAccount"  />       
<input type="button" value="upload" onclick="loadFile()" />
Upload to Sharepoint list.txtOpen
1 of 3 items
Upload to Sharepoint list.txtCSV Upload.txtsmime.p7sDisplaying Upload to Sharepoint list.txt.

以上是关于html 这会将文件上传到SharePoint库,并使用javascript和jquery从网页添加元数据。的主要内容,如果未能解决你的问题,请参考以下文章

powershell 这会将sharepoint powershell命令添加到ISE中的默认配置文件中

SharePoint2013 上传文件到文档库

powershell 这会将列表从一个SharePoint站点复制到另一个SharePoint站点

powershell 这会将内容数据库安装到SharePoint Web应用程序

html 此JavaScript将更改指向页面上SharePoint徽标的链接。默认链接转到站点主页,这会将其更改为whateve

通过 FTP 将文件上传到 Sharepoint 文档库