Basic Information

How to add the Attachment Image Silverlight control

Please follow these steps:
  1. Upload the xap as a web-resource
  2. Create a text-field that is not searchable to store the annotationid (guid)
  3. Add the Web-Resource to the form
    1. Check the checkbox to pass the id and type, etc.
    2. In the parameters add the fields and their values seperated by a pipe |
      • Example: field=new_imageattachmentid|subject='Contact''s Image'|prefix='img-'
      • Available fields are:
        • field - The name of the field you are using to store the annotationid of the attachment. It is required, and the field MUST BE ON THE FORM (it does not need to be visible).
        • subject - The subject for attachments - the following substitutions are available
          • %s - The name of the file
        • prefix - The prefix for all attachment images (this is used to filter the results, etc)
        • hidebuttons - Used to hide the buttons that are in the silverlight control so that you can use the ribbon to control the application
        • webcam - Set to true if you want to enable the webcam it is not currently tide to hidebuttons
        • savefirst - Used to set the message that is displayed on a form that is in Create Mode
        • max-width- maximum width for all images
        • max-height - maximum height for all images
        • max-webcam-width - maximum webcam image width, overrides max-width for web-cam images
        • max-webcam-height - maximum webcam image height, overrides max-height for web-cam images

TODO
Currently there is not an example of the ribbon integration - once created & tested it will be included.

NOTE
The delete button does not delete the image from the attachments it only unlinks it, clearing the ID. If you want it to delte the note, that could be done with a little bit more code in the Delete method.

Last edited Sep 19, 2011 at 2:28 AM by carltoncolter, version 5

Comments

amir65gh Apr 5, 2014 at 7:53 AM 
i want to upload only some users. whats your method for this security?

HamzaKhan Aug 1, 2013 at 1:29 PM 
Hey all,
I am a newbie to crm and I added this amazing project by Carlton Colter. I have the same issue that the image is not saving with the form, has anyone been able to solve it yet? Help would be appreciated.

ruthsmith Oct 1, 2012 at 1:48 PM 
Hi

I would like to use CRM Attachment Image I have been let down by another image programme which worked well with IE8 and IE9 but not IE7. Please confirm that CRM Attachment Image will work in IE7. Thanks!

Ruth Smith

lbeluci May 31, 2012 at 12:20 PM 
I implemented the instructions above, but it didn't work. Just a blank section is showed without buttons, or error messages. The only indication is the right click that show the silverlight properties. What can would generate this situation?

brendal Apr 25, 2012 at 8:52 PM 
I have a question on the hidebuttons control. When I added this to the parameters, the buttons still appear. Is there something I'm missing as to how to set this parameter? I've tried =True, = Yes. Still buttons show up. Otherwise this is a brilliant tool :).

dshargo Apr 24, 2012 at 2:25 PM 
I am not sure if I am doing something wrong; but after I rebuild my project and go to add the web-resource. I then go to the Form to add the resource to the form but it simply does not show up on the list. I don't see anything on any thread mentioning this, am I the only one having this issue? Any help is greatly appreciated.

carltoncolter Mar 16, 2012 at 3:13 PM 
I just updated the getServerUrl method. It was not working in onPremise deployments where the host name did not match exactly what it was in the crm config.

apham10 Feb 14, 2012 at 4:53 PM 
For those seeing the silverlight controls and having the image appear but it does not create an attachment nor does it show anything in the dropdown box. You may be using a file that is too large. I had success with image file sizes below 100kb without too long of a wait time. Originally I was trying to upload files over 1mb and that would appear as if nothing was happening for over a few minutes.

dnieto23 Jan 13, 2012 at 8:20 PM 
Hello

I used for testing prupose the component in my online trial version of Dynamics 2011 and it worked perfectly. The problem was when i tried to use it in an onpremise Dynamics 2011 rollout 5 server but the component didn't worked.

The problem is that the component cannot store the image in the note of the entity. I'm Using it in the Contact Entity, and when i'm creating the record, the process is correct, but when i try to save the record again with the image, the component doesn't save the guid of the image in the field, so the system cannot store the image. The note is not created so i don't know what i have to do.

Any one had the same issue??

Thank you

stronky Oct 27, 2011 at 10:15 AM 
Hi,

I'm having the same problem as pnagendra_007 and others: I do see the silverlight control on the form; it is possible to select a picture and this picture appears in the Silverlight control. But when I save the form, no annotations and/or notes are created. It also does not work on the server.

I noticed that the dropdown on my silverligth is empty and that there is no subject (no Contact Image). On this print screen (http://mscrmblogger.com/2011/05/10/crm-attachment-image-for-crm-2011-entities/) there is.

Any ideas what might be wrong?

Best regards, Leonard

ravikumart87 Oct 17, 2011 at 1:09 PM 
Hi,
I am facing the same issue that Nagendra has described in this post. Getting the error message

Message: Unhandled Error in Silverlight Application An error occurred while processing this request. at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)
at System.Data.Services.Client.QueryResult.EndExecute[TElement](Object source, IAsyncResult asyncResult)
at System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, IAsyncResult asyncResult)
at CrmAttachmentImage.MainPage.OnRetrieveImageAttachmentsComplete(IAsyncResult ar)
at System.Data.Services.Client.BaseAsyncResult.HandleCompleted()
at System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult)
at System.Data.Services.Client.BaseAsyncResult.<>c__DisplayClass1.<GetDataServiceAsyncCallback>b__0(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassd.<InvokeGetResponseCallback>b__b(Object state2)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback

I think this is due to some issues regarding authentication on Server side. It wont work even on Server as well. I have Virtual image of Server 2008 R2 running on Oracle VirtualBox . Please Help me on this.
Regards,
Ravi

rsquare Oct 16, 2011 at 6:05 AM 
If you can add a contact picture provider to this control it would be awesome. I have explained it in detail at then end of my blog....

http://blogs.msdn.com/b/rsquare/archive/2011/10/15/hello-msdn-uploading-and-contact-images-in-msdn.aspx

dgsosa Sep 12, 2011 at 6:56 PM 
The error was the result of the lack of configuration cross-domain access.
with the help of this post, I could make it work. : http://www.byteblocks.com/page/Using-Sockets-in-Silverlight-Diagnostics.aspx


regards
Diego

dgsosa Sep 9, 2011 at 3:00 PM 
HI.
I have the same error that says pnagendra_007, when I use it from workstations (Win 7 64bit - IE8 / 9). But if I go directly from the server (Win 2008 R2 64bit IE8) works perfectly.

Any suggestions?

Thank you so much
Diego

tobymiller28 Sep 8, 2011 at 3:12 AM 
I have implemented per the instructions above, but I don't get any output. Just a blank section. No buttons, No Text/Errors. The only indication that I have that the control is there is if I right click -- I get the silverlight menu. What am I doing wrong??

nfapi Jul 25, 2011 at 8:21 PM 
delete button not seems to unlink even the image. can you give me a tip on what the code would be to delete the image?

Latho Jul 10, 2011 at 8:11 PM 
Hi,

I like your solution very much.
The only problem we were facing is the size of the images that will expand the page load. You wrote, that you are trying to integrate a resizer?

Thx,

Thomas

carltoncolter Jun 1, 2011 at 12:33 PM 
I think NAG's problem were due to the hostname he was accessing the webserver with.

Joaolg - I am storing the annotationid in a text field to save the selection.

carltoncolter Jun 1, 2011 at 12:27 PM 
Thanks WalterN - I updated those two procedures.

pnagendra_007 May 30, 2011 at 9:23 AM 
Dear Walter,
As per your comment I replaced those two functions and compiled. After that i uploaded the file. still it's not working and also no error showing like earlier. When i upload the image it will show on the form. Then when i save, it will not save as an attachment as well as the image will disappears. And I tried the following ways
1) I kept the parameter as showed below.
field=new_imageattachmentid|subject='Contact''s Image'|prefix='img-'
Still not working.

2) I removed annotation id parameter and i kept the parameter following way:
subject='Contact''s Image'|prefix='img-'
Then it showned on the contacts' form as "There was no attachment field specified in the parameters of the Silverlight control."
I am using IE8.
Kindly help.

pnagendra_007@hotmail.com

WalterN May 26, 2011 at 2:06 PM 
I habe changed some lines of code in the file MainPage xaml.cs - and now it ist working fine.

Replace the two Functions:
// ----------------------------------------------------------------------------------------------------------------------------------------------
public void RetrieveImageAttachments()
{
var query =
(DataServiceQuery<Annotation>)Context.AnnotationSet.Where(a => a.FileName.StartsWith(FilePrefix) &&
a.ObjectId.Id == CallingObject.Id &&
(a.FileName.EndsWith(".jpg") ||
a.FileName.EndsWith(".jpeg") ||
a.FileName.EndsWith(".png")));
query.BeginExecute(OnRetrieveImageAttachmentsComplete, new object[] {"RetrieveImageAttachments",query});
}
// ----------------------------------------------------------------------------------------------------------------------------------------------
private void SetSource(Byte[] imageData)
{
MemoryStream ms = new MemoryStream(imageData);
BitmapImage im = new BitmapImage();
im.SetSource(ms);
ms.Close();
SetSource(im);
}
// ----------------------------------------------------------------------------------------------------------------------------------------------

The fist one ist a Bug-Fix: so you can choose only the Images from the Current Customer.

I don't know if ist ist neccessary - put the Text-Box with the annotationid on the Customer-Form.

PS: don't use http://localhost/... - it is not working (System.Security.SecurityException: Security error.)... - use http://myserver/...

pnagendra_007 May 24, 2011 at 2:19 PM 
Hi I tried new version. its giving the same result. please let me know whether i installed the correct way..
pnagendra_007@hotmail.com

Step 1)I added new "CrmAttachmentImage.xap" file in the Webresource.

Step 2) on this step you mentioned the parameter as

field=new_imageattachmentid|subject='Contact''s Image'|prefix='img-'
[here there is no quotations for new_imageattachmentid]

Tested but it didn't work. Then I thought you are missing the Quotations for the field (new_imageattachmentid). so I tried the following way also..

field='new_imageattachmentid'|subject='Contact''s Image'|prefix='img-'
[here i put the sing quotes for new_imageattachmentid]

When i am trying to add the image, it shows on the form area but it will not add the image under notes though u save the contact.
But still it's giving the error. As soon as form is loaded showing the following error.
Error:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC EA 2; MS-RTC LM 8; .NET4.0C; .NET4.0E; InfoPath.3)
Timestamp: Tue, 24 May 2011 14:10:12 UTC


Message: Unhandled Error in Silverlight Application An error occurred while processing this request. at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)
at System.Data.Services.Client.QueryResult.EndExecute[TElement](Object source, IAsyncResult asyncResult)
at System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, IAsyncResult asyncResult)
at CrmAttachmentImage.MainPage.OnRetrieveImageAttachmentsComplete(IAsyncResult ar)
at System.Data.Services.Client.BaseAsyncResult.HandleCompleted()
at System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult)
at System.Data.Services.Client.BaseAsyncResult.<>c__DisplayClass1.<GetDataServiceAsyncCallback>b__0(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassd.<InvokeGetResponseCallback>b__b(Object state2)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Line: 1
Char: 1
Code: 0
URI: http://serverurl/Cz/userdefined/edit.aspx?_gridType=2&etc=2&id=%7bA28A4809-EF57-E011-9AC4-00155DC8C90D%7d&pagemode=iframe&rskey=70547549&sitemappath=Workplace%7cCustomers%7cnav_accts


Message: Unhandled Error in Silverlight Application An error occurred while processing this request. at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)
at System.Data.Services.Client.QueryResult.EndExecute[TElement](Object source, IAsyncResult asyncResult)
at System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, IAsyncResult asyncResult)
at CrmAttachmentImage.MainPage.OnAnnotationRetrieved(IAsyncResult ar)
at System.Data.Services.Client.BaseAsyncResult.HandleCompleted()
at System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult)
at System.Data.Services.Client.BaseAsyncResult.<>c__DisplayClass1.<GetDataServiceAsyncCallback>b__0(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassd.<InvokeGetResponseCallback>b__b(Object state2)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Line: 1
Char: 1
Code: 0
URI: http://serverurl/cz/userdefined/edit.aspx?_gridType=2&etc=2&id=%7bA28A4809-EF57-E011-9AC4-00155DC8C90D%7d&pagemode=iframe&rskey=70547549&sitemappath=Workplace%7cCustomers%7cnav_accts

pnagendra_007 May 22, 2011 at 1:12 PM 
Hi,
When i add first time it was saving the image and showing. After 3 days i observed it's not saving and also not showing some error is showing as soon as i uploading.

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC EA 2; MS-RTC LM 8; .NET4.0C; .NET4.0E; InfoPath.3)
Timestamp: Sun, 22 May 2011 13:15:56 UTC


Message: Unhandled Error in Silverlight Application An error occurred while processing this request. at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)
at System.Data.Services.Client.QueryResult.EndExecute[TElement](Object source, IAsyncResult asyncResult)
at System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, IAsyncResult asyncResult)
at CrmAttachmentImage.MainPage.OnRetrieveImageAttachmentsComplete(IAsyncResult ar)
at System.Data.Services.Client.BaseAsyncResult.HandleCompleted()
at System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult)
at System.Data.Services.Client.BaseAsyncResult.<>c__DisplayClass1.<GetDataServiceAsyncCallback>b__0(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassd.<InvokeGetResponseCallback>b__b(Object state2)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Line: 1
Char: 1
Code: 0
URI: http://ServerUrl/userdefined/edit.aspx?_gridType=2&etc=2&id=%7b297C9FC0-EC57-E011-9AC4-00155DC8C90D%7d&pagemode=iframe&rskey=548940451&sitemappath=Workplace%7cMyWork%7cnav_dashboards

joaolg May 20, 2011 at 5:20 PM 
Hi.
I'm a rookie at this activity, so be patient, please.
About the step 2, what is the way to store the annotationid or the attachment in this text-field.
Thanks,
João.
joaolg@hotmail.com