Web Resource creation through SDK message

For a web resource creation through SDK, i referred one msdn page click. In this page they read a text file convert them into binary content and then converted into base64 string.

In my case i had HTML on CRM form Fields, so i fetch the field in Plugin and converted its content into binary format and finally into base64 string. the code for which goes as follows

               string JSContent = TileConfiguration.Attributes[“livetile_jscontent”].ToString();

                string HTMLContent = TileConfiguration.Attributes[“livetile_htmlcontent”].ToString();

                var bytes = Encoding.UTF8.GetBytes(JSContent + HTMLContent);

                var base64 = Convert.ToBase64String(bytes);

                //Set the Web Resource properties

                WebResource wr = new WebResource

                {

                    Content = base64,

                    DisplayName = “Test1”,

                    Description =”Sample Test”,

                    Name = “livetile_” +”test1″,

                    LogicalName = WebResource.EntityLogicalName,

                   //you can specify type for web resource format

                   Webpage (HTML).htm, .html1
                    Style Sheet (CSS).css2
                    Script (JScript).js3
                    Data (XML).xml4
                    Image (PNG).png5
                    Image (JPG).jpg6
                    Image (GIF).gif7
                    Silverlight (XAP).xap8
                   StyleSheet (XSL).xsl, .xslt9
                     Image (ICO).ico10

                    WebResourceType = new OptionSetValue(1)

                };

                CreateRequest cr = new CreateRequest

                {

                    Target = wr

                };

                //Set the SolutionUniqueName optional parameter so the Web Resources will be

                // created in the context of a specific solution.

                //cr.Parameters.Add(“SolutionUniqueName”, _ImportWebResourcesSolutionUniqueName);

                CreateResponse cresp = (CreateResponse)service.Execute(cr);

To update the same web resource, You can do it using UpdateRequest, the code for which goes like below

                WebResource wr = new WebResource

                {

                   //Just pass the web resource ID

                    Id = new Guid(TileConfiguration.Attributes[“livetile_webresourceid”].ToString()),

                    Content = base64,

                    DisplayName = “Test1”,

                    Description = “Sample Test”,

                    Name = “livetile_” + “test1”,

                    LogicalName = WebResource.EntityLogicalName,

                    WebResourceType = new OptionSetValue(1)

                };

                UpdateRequest up = new UpdateRequest

                {

                    Target = wr

                };

                service.Execute(up);

Thanks.

Leave a comment