2012-09-27 24 views
0

我需要使用Java腳本的圖像文件上傳到SharePoint 2010的圖片庫上傳圖像文件到SharePoint 2010的圖片庫......如何使用ECMA腳本

的要求是 -

1.我們有文件上傳控制

2.And,我們必須從該文件上傳控件

請參閱代碼上傳圖像文件......但是,這代碼不工作(顯示「文件」「未定義的對象」異常或'FileInfo')

如果任何機構有更好的解決方案,將是很好的。

在此先感謝。

<script> 
var clientContext = new SP.ClientContext.get_current(); 
var oList = clientContext.get_web().get_lists().getByTitle('Test'); 
//var fStream = (new FileInfo(uploadimagepath)).OpenRead(); 
var fStream = File.OpenRead(uploadimagepath); 
//var fStream = FileUpload.PostedFile.InputStream; 
//var contents = new byte[fStream.Length]; 
var newPic = oList.RootFolder.Files.Add(phototitle, fStream); 
var oItem = newPic.Item; 
oItem.set_item('Title', phototitle); 
oItem.update(); 
oList.Rootfolder.Update(); 
clientContext.load(oItem); 
</script> 

回答

0

你不能使用uploadimagepath,它會給你從客戶端的路徑。

而是使用其從客戶端發送到服務器的文件流。

檢查這個網址對於理解文件上傳控制更好

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.postedfile.aspx

+0

Link是關於C#,但我有在SharePoint 2010中使用Java腳本(ECMAScript)。我也在我的代碼中使用了文件上傳控件(請參閱註釋行......),但文件上傳控件也有相同的異常。 –