標籤:crm 2013 crm
上傳附件可能是CRM裡比較常用的一個需求了,本文將介紹如何在CRM裡實現附件的上傳、顯示及下載。包括以下幾個步驟:
- 附件上傳的web頁面
- 附件顯示及下載的附件實體
- 調用上傳web頁面的JS檔案
- 實體上r的上傳按鈕
先點擊上面的上傳按鈕,然後就會彈出一個上傳附件的介面,選擇需要上傳的檔案,填寫檔案名稱,點擊上傳,成功後會在下面的檔案grid裡顯示已上傳的檔案,雙擊下面的檔案就會開啟檔案的詳細資料:
然後還可以下載檔案。
1. 附件上傳的web頁面
建立一個普通的web程式,加上一個aspx頁面用於實現檔案上傳,這裡用的是jquery裡的uplodify:
這是實現上傳的js代碼
1: $( document ).ready( function ()
2: {
3: uploadFiles();
4: } );
5:
6: function uploadFiles()
7: {
8: $( "#uploadify" ).uploadify( {
9: ‘swf‘: ‘Scripts/upload/uploadify.swf‘,
10: ‘uploader‘: ‘uploader.ashx‘,
11: ‘queueID‘: ‘fileQueue‘,
12: ‘auto‘: false,
13: ‘multi‘: true,
14: ‘onUploadError‘: function ( file, errorCode, errorMsg, errorString )
15: {
16: alert( ‘The file ‘ + file.name + ‘ could not be uploaded: ‘ + errorString );
17: },
18: ‘onUploadSuccess‘: function ( file, data, response )
19: {
20: $( ‘<li><a href="‘ + data + ‘">‘ + file.name + ‘</a></li>‘ ).appendTo( $( ‘ul‘ ) );
21: }
22: } );
23: }
24:
25: function Upload()
26: {
27: $( ‘#uploadify‘ ).uploadify( ‘upload‘, ‘*‘ );
28: }
這是頁面上顯示的內容:
1: <table class="GbText">
2: <tr>
3: <td>
4: <input type="file" name="uploadify" id="uploadify" />
5: </td>
6: <td>
7: <input type="button" value="Upload Files" class="uploadify-button" style="height:25px; width: 112px;" onclick="javascript: $( ‘#uploadify‘ ).uploadify( ‘upload‘, ‘*‘ )" />
8: <input id="yes" class="Button" onclick="UpFiles();" onmouseout="this.className=‘Button‘" onmouseover="this.className=‘Button-Hover‘" style="width:50px" type="button" value="Confirm" />
9: </td>
10: </tr>
11: <tr>
12: <td colspan="2">
13: <ul id="ul"></ul>
14: </td>
15: </tr>
16: </table>
17: <div id="fileQueue">
最後把它放到ISV下面:
2. 附件實體
紅框中的欄位為lookup類型,需要實現上傳功能的實體的id,其餘為基本欄位
中間紅框中是一個iframe, 其它沒什麼介紹的:
1: var uploadCfg = {
2: fileFloder: Xrm.Page.data.entity.getEntityName(),
3: entityReferenceName: Xrm.Page.data.entity.getEntityName() + "id",
4: entityName: Xrm.Page.data.entity.getEntityName().toLowerCase()
5: };
6:
7: function uploadFile() {
8: var openURL = "/ISV/FilesUpload/FileUpload.aspx?FileFolder=" + uploadCfg.fileFloder + "&EntityName=" + uploadCfg.entityName
9: + "&EntityReferenceName=" + uploadCfg.entityReferenceName + "&EntityId=" + Xrm.Page.data.entity.getId()
10: + "&UserId=" + Xrm.Page.context.getUserId();
11: window.showModalDialog(openURL, "_blank", "dialogWidth=500px;dialogHeight=300px;help:no;status:no"); //開啟模態表單
12: }
添加按鈕並指定function名uploadFile
/_imgs/ribbon/AddConnection_16.png
uploadFile
$webresource:new_upload_file.js
Dynamic CRM 2013學習筆記 系列匯總
Dynamic CRM 2013學習筆記(十三)附件上傳 / 上傳附件