Thursday, November 16, 2017

Removing XML Nodes from a XML Document

Following code can be used to remove a XmlNode with all the children nodes

      XmlDocument doc = new XmlDocument();
        doc .Load(MapPath("~/FileName.xml"));
        XmlNodeList selectedNodes = doc .SelectNodes("//SubNode");
      
       foreach (XmlNode node in selectedNodes )
        {
            node.ParentNode.RemoveChild(node);
        }

Regards,
Samitha

Thursday, November 2, 2017

IIS error accessing WCF (HTTP Error 404.3)

When accessing a WCF service through browser, you  might have encountered following IIS error.

HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

This occurs due to a feature in IIS which is not turned on by default.


This issue can be solved through following steps.

  1. From Control Panel -> Programs and Features -? Turn Windows features on or off.
  2. Click.NET Framework 4.6 Advanced Services - WCF Services (actual framework version may change)
  3.  Select HTTP Activation
  4. Ok

 

Wednesday, October 4, 2017

jquery paste event

You can use the jQuery paste event on any textbox/editor as shown below. It is supported by all modern browsers.

Following example shows handling numeric values on key press and past.

 <script type="text/javascript">

 function pageLoad() {
  $("#controlID").on('paste, keydown', function e() {
        return isNumericKey(e);
  });
 }
 
function isNumericKey(e) {
    var charInp = window.event.keyCode;
        if (charInp > 31 && (charInp < 48 || charInp > 57)) {
            return false;
        }
        return true;
  }
 
</script> 
 
Cheers,
Samitha 

Wednesday, August 30, 2017

Refused to display in a frame because it set 'X-Frame-Options' to 'DENY'

You might Sometimes encounter the error above when you are using iframes w to load resources outside from the domain.

This Issue can be fixed in two ways

1) Add this to web.config

<httpProtocol>
    <customHeaders>
      <add name="X-Frame-Options" value="AllowAll" />
    </customHeaders>
  </httpProtocol>

2) Add this to Global.asax.cs

protected void Application_PreSendRequestHeaders()
{
 Response.Headers.Remove("X-Frame-Options");
 Response.AddHeader("X-Frame-Options", "AllowAll");
}
 
Please read this discussion in stackoverflow for a detailed discussion on the topic.

Regards,
Samitha


Wednesday, August 9, 2017

drop database user that owns a schema


First you will have to determine the schema's owned by a given user in order to  drop the user.

Execute the following query to determine the schemas owned by the user  named ‘user1’ .

SELECT name FROM sys.schemas
WHERE principal_id = USER_ID('user1');

When you run the query above, suppose you get db_datawriter as the schema owned by user (in this case user1)

Next step is to change the owner of the schema db_datawriter to some other user (e.g. dbo):

ALTER AUTHORIZATION ON SCHEMA::db_datawriter TO dbo;



You will have to remove all the schemas to drop a db user. When the user has no schemas owned you can drop it.


Friday, July 14, 2017

Retrieve the uploaded file extension from JavaScript

Following java script unction can be used to get the extension of a uploaded file.

function getFileExtension(fileName)
{
  var extension = /^.+\.([^.]+)$/.exec(fileName);
  return extension == null ? "" : extension [1];
}

Cheers
Samitha

Tuesday, June 27, 2017

Enable/Disable button when checkbox clicked

This can be easily achieved using jQuery as displayed below.

//bind this event in pageLoad or Dom Ready

$("#chkAgree").click(function(e) {
  $("#btnSave").attr("disabled", !this.checked);
});

Regards,
Samitha