As I work through the customizations for the customer portal. I am very impressed with the OOB functionality that is already in this version as opposed to what was available with eService.
For eService I had to add features like, displaying both Closed and Active cases and add the filter functionality. I was very pleased to see this type of thing was already in the Customer Portal.
Another feature that was not available was for documents that were attached as a notes for service cases. It was fairly easily to add this functionality to eService and I was very excited to see that this functionality appeared available in Customer Portal. Well not exactly. I have not verified this completely but the link in the code resolved to _entity/annotation/Guid . After scouring the code, the pages templates, links, and pretty much everywhere I could not find where this was supposed to be going. It is possible that something was configured incorrectly, but with time of the essence in an upgrade situation, I decided to rework the code I wrote for eService.
First you will need to change the URL on the editcase.aspx page to point to the page we are going to create. I commented out the line of code that was there and the second line is the code that points to our new page.
<%--<asp:HyperLink CssClass="note-attachment" NavigateUrl='<%# (Container.DataItem as Entity).GetRewriteUrl() %>' Visible='<%# Eval("FileSize") != null %>' runat="server"><%# Eval("FileName") %> (<%# Eval("FileSize") %>)</asp:HyperLink>--%> <asp:HyperLink ID="HyperLink1" CssClass="note-attachment" NavigateUrl='<%# Eval("AnnotationId", "~/pages/eservice/download.aspx?annotationid={0}") %>' Visible='<%# Eval("FileSize") != null %>' runat="server"><%# Eval("FileName") %> (<%# Eval("FileSize") %>)</asp:HyperLink>
Then I added a page to my Customer Portal Project called download.aspx. Then I removed all code from the page except for the declaration at the top of the page. In the code we are going to use the Response.OutPutStream.Write to basically convert this page to the document you are downloading.
below is the only line of code necessary for aspx page.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="download.aspx.cs" Inherits="Site.Pages.eService.download" %>
then in the code behind:
using Microsoft.Xrm.Sdk.Client; using Microsoft.Xrm.Sdk.Query; using Xrm; using System.Linq; using Microsoft.Xrm.Portal.Access; using Microsoft.Xrm.Portal.Cms; using Microsoft.Xrm.Portal.Core; namespace Site.Pages.eService { public partial class download : PortalPage { private Guid _annotationId; protected void Page_Load(object sender, EventArgs e) { if (!String.IsNullOrEmpty(Request.QueryString["annotationid"])) { _annotationId = new Guid(Request.QueryString["annotationid"]); } //create a new context to the Xrm to pull the annotationset back var contextnote = new Xrm.XrmServiceContext("Xrm"); var retrievedAnnotation = ( from note in contextnote.AnnotationSet where note.AnnotationId == _annotationId select new { note.FileName, note.DocumentBody, note.FileSize, note.MimeType } ); //loop thorugh the return to create the out put stream. foreach (var annotation in retrievedAnnotation) { Response.ContentType = annotation.MimeType; byte[] buffer = Convert.FromBase64String(annotation.DocumentBody); int filesize = buffer.Length; Response.AddHeader("content-disposition", "attachment; filename=" + annotation.FileName); Response.OutputStream.Write(Convert.FromBase64String(annotation.DocumentBody), 0, filesize); } } } }
So in the code you are requesting the GUID from url and then passing that to the linq to sql querry which brings back all the infromation you need to generate the document.
Feel free to comment and let me know what you think.
Love the modern appear. I was pleased with this article. Appreciation for a fine blog post. alle werbemittel tasse tasse werbemittel
LikeLike
thank you, glad you find the information helpful.
Dorothy
LikeLike
Miss America 2011…
LikeLike
Nice Blog…I love to read your posts.
LikeLike
thank you.
Dorothy
LikeLike
A better magazine theme will make the blog looks nicer:)
LikeLike
Great article! I loved the insight and advice given. In addition, your blogging style is very fun to read. If you have time please take a look at my brand new blog and tell me what you think.
LikeLike
What a great article! Thanks and keep up the great work!
LikeLike
Have you found a way to do this within CRM 2011 ? I’d like to implement a list of attachments with clickable URLs through a SSRS report (dashboard), but I’haven’t found a way to provide the base64 decoding required to open the attachment directly (that is, not going through opening the note first).
LikeLike
I have not had the need within CRM. I am going to take a look at this and see what I can figure out. sounds like a nice little challenge
LikeLike
Do you guys have any feedback on the above? i have similar requirements and was wondering if this is possible?
LikeLike
Hi Charmaine,
Can you give a little better idea what kind of solution you are looking for.
thanks,
Dorothy
LikeLike
What an awesome article. Thank you and keep up the good work.
LikeLike
It is also downloading the page source along with file content.
LikeLike
we need to add Respone.End()
LikeLike
Thanks Reddy, I will make the update.
LikeLike
can you elaborate please?
LikeLike