Uploading attachments may be a common requirement in CRM, this article will introduce how to implement the attachment upload, display and download in CRM. The following steps are included:
- Web page for attachment upload
- Attachment display and downloaded attachment entities
- Invoke JS file to upload Web page
- Upload button for R on entity
- First look at the effect:
First click on the Upload button above, then will pop up an upload attachment interface, select the file to upload, fill in the filename, click Upload, successful will be in the following file grid to display the uploaded files, double-click the following file will open the file details:
You can then also download the file.
- Here's a look at the implementation method
1. Web pages uploaded by attachments
Create a new normal Web program, plus an ASPX page for file uploads, using the uplodify in jquery:
This is the JS code to implement the upload
1: function ()
2: {
3: uploadfiles ();
4: });
6: function uploadfiles ()
7: {
8: $ ("#uploadify"). Uploadify ({
9: ' swf ': ' scripts/upload/uploadify.swf ',
Ten: ' uploader ': ' Uploader.ashx ',
One: ' queueid ': ' Filequeue ',
: ' auto ': false,
: ' multi ': true,
: ' onuploaderror ': function (file, ErrorCode, ErrorMsg, errorstring)
: {
: ' the file ' + File.name + ' could not being uploaded: ' + errorstring ';
: },
: ' onuploadsuccess ': function (file, data, response)
: {
: ' <li><a href= ' + data + ' "> ' + file.name + ' </a></li> '). AppendTo ($ (' ul '));
: }
: });
: }
: function Upload ()
: {
: ' #uploadify '). Uploadify (' upload ', ' * ');
: }
This is what is displayed on the page:
1: 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= "Yesclass="button"onclick="upfiles ();"onmouseout=" This.classname= ' button '"onmouseover="this.classname= ' button-hover '"style="width:50px" Type= "button" value= "Confirm"/>
9: </td>
Ten: </tr>
One: <tr>
: <td colspan= "2" >
: <ul id= "ul" ></ul>
: </td>
: </tr>
: </table>
: <div id= "filequeue" >
Finally put it under the ISV:
2. Attachment Entities
The fields in the red box are the lookup type, the ID of the entity that needs to implement the upload function, and the rest is the basic field
The Middle red box is an IFRAME, and nothing else is introduced:
- Invoke JS file to upload Web page
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:};
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 ()
Ten: + "&userid=" + Xrm.Page.context.getUserId ();
One: windowshowmodaldialog (OpenURL, "_blank", "dialogwidth=500px;dialogheight=300px; Help:no;status:no"); //Open modal form
12:}
Add a button and specify the function name UploadFile
Dynamic CRM 2013 Learning Notes Series Rollup
Dynamic CRM 2013 Learning Notes (13) Attachments upload/upload attachments