Thursday, January 23, 2014

Resolve C:\fackpath in upload field instead o the full path

For the security reason this fackpath introduced and there is no way to show the actual path instead of the fackpath.

Just one way to replace the fackpath and show only the uploaded file name.

// check for IE's lovely security speil
if(filePath.match(/fakepath/)) {
  // update the file-path text using case-insensitive regex
  filePath = filePath.replace(/C:\\fakepath\\/i, '');
}

To replace the "\" in the URL use the below line of code.


this.value.replace(/\\\\/g, '');


Post data from client to a web service (.asmx, .svc) in C#

If you want to post data from your web application to web service then use the below line of code and change it according your requirement.

ClientSection clientSettings = ConfigurationManager.GetSection("system.serviceModel/client"as ClientSection;
                string address = string.Empty;
                foreach(ChannelEndpointElement endpoint in clientSettings.Endpoints)
                {
                    if (endpoint.Name == "WarrantyXServiceSoap")
                    {
                        address = endpoint.Address.ToString();   
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(address))
                {
                    HttpWebRequest request;
                    string url = WebService URL;
                    string action = "http://tempuri.org/MethodName";

                    request = (HttpWebRequest)WebRequest.Create(url);
                    request.Method = "POST"; // OR "GET" if you want to make a GET request 
                    request.ContentType = "text/xml; charset=utf-8";
                    request.Headers.Add("SOAPAction: " + action);

                    StringBuilder soapRequest = new StringBuilder("");
                    soapRequest.Append("http://www.w3.org/2001/XMLSchema-instance\
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
                    soapRequest.Append("");
                    soapRequest.Append("http://tempuri.org/\
">");
// these are the parameters of web method to pass data from client machine
                    soapRequest.Append("" + _Name + "
");
                    soapRequest.Append("" + Convert.ToBase64String(_BinaryDoc) + "
");
                    soapRequest.Append("" + _ContentType + "
");
                    soapRequest.Append("" + _ID.ToString() + "
");

                    soapRequest.Append("
");
                    soapRequest.Append("
");
                    soapRequest.Append("
");

                    request.ContentLength = soapRequest.ToString().Length;
                    request.KeepAlive = false;
                    request.Timeout = System.Threading.Timeout.Infinite;
                    request.AllowWriteStreamBuffering = false;
                    request.ProtocolVersion = HttpVersion.Version10;
                    request.ServicePoint.ConnectionLeaseTimeout = 600000;
                    request.ServicePoint.MaxIdleTime = 600000;
                    request.Proxy = null;
                    request.ReadWriteTimeout = 600000;
                    request.Accept = "text/xml";

                    using (Stream requestStream = request.GetRequestStream())
                    {
                        using (StreamWriter requestStreamWriter = new StreamWriter(requestStream))
                        {
                            requestStreamWriter.Write(soapRequest.ToString());
                        }
                    }

                    string result = string.Empty;
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        StreamReader reader = new StreamReader(response.GetResponseStream());
                        result = reader.ReadToEnd();
                    }

                    var xDoc = XDocument.Parse(result);
                    _createdAnnotation = new Guid(xDoc.Root.Value);

                }

How do I upload large greater than 5MB files to a web service?

I have a web service that takes a serialize string and saves it.
This works fine for "small" files, but once I hit a large size the web service fails and returns "The request failed with HTTP status 404: Not Found."
From what I've seen this appears to be an IIS setting that limits the size of a file that can be posted. I've tried to increase that setting, but I am having trouble determining what setting and where/how one would set it. I am using IIS7 and the webservice is done in .net (asmx).
In the web.config of the web service I have added the following (which seemed to increase the size of file that can be accepted, but not all the way to this setting size)
IIS 6

 <system.web>
     <httpRuntime executionTimeout="999999" maxRequestLength="2097151" />
     ...
  </system.web>
IIS7
   <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2000000000" />
      </requestFiltering>
    </security>
  </system.webServer>
   
     
       
     
   
 



Sunday, January 19, 2014

LINQ - Concat a column value by a Unique ID

Table 1:

Number               City       
111                         Delhi     
111                         Agra      
112                         Jaipur   
111                         Hapur   
113                         Jodhpur              

Table 2

Number(Unique)  Percent
111                                         10
112                                         20
113                                         30


Output Required

Number                               Cities                             Percent
111                         Delhi ,Agra ,Hapur                           10
112                                         Jaipur                               20
113                                         Jodhpur                            30


By Linq

var varContact = from t2 in Table2.AsEnumerable()
                                    
                 join t1 in Table1.AsEnumerable() on t1.Field("Number") equals t2.Field("Number") into t1t2
                 select new
                 {
                                     Number = t2.Field("Number"),
                     Cities = t1t2.Where(x => x.Field("Number").ToString().Equals(c.Field("Number").ToString())).Select(g => g.Field("City")).Aggregate((i, j) => i + " ," + j),
                     Percent = c.Field("Percent")
                                        

                 };

Wednesday, January 15, 2014

Create a CRM 4.0 lookup user control in ASP.NET

I got one requirement In a project related to CRM to create a lookup user control with look and feel same as lookup control in MS CRM 4.0

After spending some days Me and Team successfully developed the CRM 4.0 lookup control. To include it in the page just add two below lines in the page.

1- Register the "ascx" Control in a page

<%@ Register Src="Controls/LookupControl.ascx" TagName="LookupControl" TagPrefix="ucLkp" %>

2- to use at your location just add this line

<ucLkp:LookupControl ID="lkpAnsWbs" runat="server" />

If you have any requirement to develop the same type of control then please put a comment in this post to find a code.

Correct way to pass data or parameters in JSON call.

Some times ago I was working on the project with JSON call and at the time my requirement to pass some data from outside by variables in the JSON. I tried various ways to pass data but did not find any success, I have also google multiple sites and blogs but not able to find the solution. finally I got the solution after some hidden trial.

There are two ways to pass the data in JSON

1- Pass data as Array

            var arr = {};
            arr.FetchXML = fetchXml;
            arr.LayoutXML = layoutXml;
            arr.EntityName = entityName;
            arr.DefaultAdvFindViewId = defaultAdvFindViewId;
            arr.ViewType = 1039;
            arr.SortCol = sortCol;
            arr.SortDescend = sortDescend;

            $.ajax({
                type: "POST",
                contentType: "application/x-www-form-urlencoded",
                datatype: "json",
                url: url,
                data: arr,
                timeout: timeoutvalue,
                beforeSend: function (XMLHttpRequest) {
                    //Specifying this header ensures that the results will be returned as JSON.
                    XMLHttpRequest.setRequestHeader("Accept", "application/json");
                },
                success: function (data, textStatus, XmlHttpRequest) {
                    PushResponseContents(iFrame, XmlHttpRequest, entityTypeId);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //errorHandler(XMLHttpRequest, textStatus, errorThrown);
                    //alert(textStatus);
                    //alert(errorThrown);
                    doc.open();
                    doc.write("");
                    doc.close();
                    alert("Request Timeout. Please refine your search criteria");
                }
            });

2- Pass data as parameter

$.ajax({
            type: "POST",
            url: "http://" + location.hostname + "/ISV/",
            data: "{\"id\":'" + id + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                // alert(response);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                //alert(jqXHR);
                //alert(textStatus);
                //alert(errorThrown);
            }

        });

Note: If this blog help to find/resolve your query then please comment.

Split the String values with a special character in MS Flow to convert this into Array

 Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, ...