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>
   
     
       
     
   
 



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, ...