Tuesday, March 16, 2010

Solving Issues with opening/Downloading attachments in Notes after Rollup 7

Downloading Notes in MS CRM

        We can download the attachments of Notes by framing the Following URL.

     But this approach works only when we don't have roll-up 7 on the system.
After installing the roll-up above 6 , this approach won't works,because security tokens will be added to this link.So it gives error as "INVALID_WRPC_TOKEN"

     so one of the best approach i know to solve this issue is as follows,

public byte[] DownloadAttachment(string AnnotationId)
            Guid annotationId = new Guid( AnnotationId );

            // Define the columns to retrieve from the annotation record.
            ColumnSet cols1 = new ColumnSet();
            cols1.Attributes = new string[] { "filename", "documentbody" };

            // Retrieve the annotation record.
            annotation annotationAttachment = (annotation)crmService.Retrieve(EntityName.annotation.ToString(), annotationId, cols1);

            using (FileStream fileStream = new FileStream(annotationAttachment.filename, FileMode.OpenOrCreate))
                byte[] fileContent = new UTF8Encoding(true).GetBytes(annotationAttachment.documentbody);
            //    fileStream.Write(fileContent, 0, fileContent.Length);

                return fileContent;

In the Download Button Click Event,

 byte[] fileData = DownloadAttachment(annotationID);

            Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
            BinaryWriter bw = new BinaryWriter(Response.OutputStream);
            Response.ContentType = mimetype;

Monday, March 1, 2010

Retrieving appsettings keys & display in drop down list

//Retrieving appsettings keys & display in drop down list
        ArrayList entitylist=new ArrayList();
        Configuration config = WebConfigurationManager.OpenWebConfiguration("~");      

            // Get the appSettings.
            KeyValueConfigurationCollection appSettings =  config.AppSettings.Settings;

           foreach (string key in appSettings.AllKeys)
           ddl_entitylist.DataSource = entitylist;

Placing a report in the IFrame with GUID as parameter

//Placing a report in the IFrame without asking for credentials

   //get guid of form
var guid= crmFormSubmit.crmFormSubmitId.value;
guid = guid.substring(1, guid.length -1)

var url = "http://server/ReportServer?/Myreport&rs:Command=Render&rc:Toolbar=false&Guid="+ guid;

document.getElementById('IFRAME_Report').src = url;

Calling custom webservice using java script

 //Calling custom web service using java script

var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                var soapXml = "<?xml version='1.0' encoding='utf-8'?>";
                soapXml += "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";
                soapXml += "<soap:Body>";
                soapXml += "<GetObjectTypeCode xmlns='http://tempuri.org/'>";
                soapXml += " <Entity>" + entityname + "</Entity>";
                soapXml += " </GetObjectTypeCode>";
                soapXml += " </soap:Body>";
                soapXml += "</soap:Envelope>";

                xmlhttp.open("POST", "/customwebserviceurl.asmx", false);
                xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                xmlhttp.setRequestHeader("Content-Length", soapXml.length);
                xmlhttp.setRequestHeader("SOAPAction", "http://tempuri.org/GetObjectTypeCode");

                var resultValue = xmlhttp.responseXML.childNodes[1].nodeTypedValue;