infopath上傳attachment

來源:互聯網
上載者:User
著作權聲明:原創作品,允許轉載,轉載時請務必以超連結形式標明文章 原始出處 、作者資訊和本聲明。否則將追究法律責任。http://zhonglei.blog.51cto.com/1159374/268587
原文:http://www.bizsupportonline.net/blog/2010/01/upload-document-sharepoint-infopath-form/ by S.Y.M. Wong-A-Ton 本文指導我們如何使用代碼從InfoPath表單中將附件抽取並且上傳到SharePoint中。 如下代碼,可以把InfoPath中名為Document的附件控制項中的檔案,上傳到SharePoint中名為MyDocuments的文件庫中。 具體操作是在表單上添加一個按鈕,然後在按鈕上添加VSTA代碼,添加下面的代碼。 在整個程式中,使用了 InfoPathAttachmentDecoder 類,這個類的編寫方法請參照微軟的官方文章http://support.microsoft.com/kb/892730。 

// Retrieve the value of the attachment in the InfoPath form
XPathNavigator ipFormNav = MainDataSource.CreateNavigator();
XPathNavigator nodeNav = ipFormNav.SelectSingleNode(
"//my:document", NamespaceManager);

string attachmentValue = string.Empty;
if (nodeNav != null && !String.IsNullOrEmpty(nodeNav.Value))
{
attachmentValue = nodeNav.Value;

// Decode the InfoPath file attachment
InfoPathAttachmentDecoder dec =
new InfoPathAttachmentDecoder(attachmentValue);
string fileName = dec.Filename;
byte[] data = dec.DecodedAttachment;

// Add the file to a document library
using (SPSite site = new SPSite("http://ServerName"))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPFolder docLib = web.Folders["MyDocuments"];
docLib.Files.Add(fileName, data);
web.AllowUnsafeUpdates = false;
web.Close();
}
site.Close();
}
} 需要注意的是,你需要在VSTA工程中引用SharePoint dll並且添加對Microsoft.SharePoint名字空間的引用。然後給InfoPath表單完全的安全信任,以便代碼可以訪問SharePoint資源。

本文出自 51CTO.COM技術部落格

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.