Dynamic CRM 2013學習筆記(十三)附件上傳 / 上傳附件

來源:互聯網
上載者:User

標籤: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, 其它沒什麼介紹的:

 

  • 調用上傳web頁面的JS檔案
  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學習筆記(十三)附件上傳 / 上傳附件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.