Sunday, February 1, 2015

Ctrl right click open folder in Command window

Here I'm adding an very simple but amazing tip to open and switch to a specific folder directily instead of opening  the command window and type multiple DOS steps to move the command line cursor to the specific folder.

From Window explorer, Shift+Right Click on the folder you will get an additional context menu. See below


Once you click it will open the command window directly points to that directory.


Thats it!... Cool. It saves a lot of you time and confusions

Happy coding (Y)

Reference : http://www.hanselman.com/blog/QuakeModeConsoleForVisualStudioOpenACommandPromptWithAHotkey.aspx

Wednesday, March 14, 2012

WCF is Case sensitive


All my communications now a days are fully founded. Its a communication foundation, especially or more specific its Windows Communication Foundation. Everywhere now it clearly visible for the passion for services beyond channel limits. Its a passion of unbound of either HTTP or Networked.

So whats new in this. Yes it is... We were in a task. Scheduled or taken whatever, finally it got assigned to us. Job was very simple convert a running HTTP WCF library to NetTcp. I have my great passionate technologist and code innovator colleague with me. I just came here with my high expectation and confidence of last HTTP Bound service implementation in previous project. But he is now a master, really the last word of the TCP bound service running in our project.

Everything was ready in my machine. A HTTP bound WCF service running. I tested the service with adding it to the a console application. That works great! Now the task is the conversion to “net.tcp”.
Very simple as we thought. Changed the app.Config “Binding”


<endpoint address ="" binding="NetTcpBinding" contract="WcfServiceLibrary1.IService1">


Nothing works it continued to throw the same error message 


system.serviceModel/bindings/NetTcpBinding' could not be found. Verify that this binding extension is properly registered in system.serviceModel/extensions/bindingExtensions and that it is spelled correctly.”


Even when we tried to switch back to the old “WSHttpBinding”. That also now stopped to work. Jumpled!. As like my friend's T-shirt caption, we are now really “Screwed”! Whats next? he asked me. Go to the simple . We added another new WCF project to the same solution just ran to check the “Hello world” method running. It was calm and smooth.

Then where we are wrong?

Simple, we compared the App.Configs side by side. Makes sense! Straight forward ! Its not your Web.config as we always do. Its WCF syntax which is very sensitive in each case of its implementation. Or its pure CASE SENSITIVE. Our “NetTcpBinding will not work. You have to start it with a small “n” always. Yes thats the answer.


<endpoint address ="" binding="netTcpBinding" contract="WcfServiceLibrary1.IService1">


My friend was jumping! “I knew it! I had seen it”... Yeah I know, he really knows it....  




Monday, September 20, 2010

SVN (Sub version) Export - remove svn files from code

In most of my programming career mainly I saved my codes in SVN(Subversion). So i have deep relationship with SVN. The main reason this always prefer to walk with SVN might be I think its simplicity, straight forward and fastest bidirectional code update.

I start my coding definitely with SVN, but later I moved to MS source safe(VSS). Since all my development I did with Visual studio, Source safe gave good support for me from the studio. But the poor performance of Source safe every time annoyed and it always brought that sweet thoughts of SVN. The big advantage here I've seen in Source safe was the easy isolation of Version control files and folders from the code files.

If you add your project to the SVN it'll add a "-svn" folder everywhere (inside every folder) in the project. So at the time of deployment everytime you have to go inside each and every folder and have to remove this svn folder(the reason for this svn removal is some time these files may create permission issues in the deployed server while manages with FTP). But in the case of Source safe everything manages with a single source file (project name.vss). So here things can do very easily.

When ever I do this file removal with SVN, I always would think about a simple solution probably hidden under SVN bunk. But truth is I never tried for that. The reason I again can tell most of my recent works I manages with VSS.

But recently, I was involving in big project deployment to a new server, the same concern came to me and I was really worried on how to remove these file from this big sized project which has thousands of folders under. I talked few of the senior people, but everyone has not much idea on SVN. Most of them worked only with VSS and they were well sounded in that(also I understood how much .Net people trust on their fully supported Source safe, even its poor performance ).

Instead of start my work I was sitting my seat, thinking. But the real truth once again got proved for me that "simplification will always happen whenever you approach things as simple". I simply discussed the context with one of my colleague who has comparatively less experienced there. He said he also doesn't have much knowledge in SVN, but in the past he heard some statements from his managers at the deployment time, they used the word "Export".

Yes, that was enough for me.. I jumped into my SVN context menu to know what is "export" or anything is there like that. Of course that was the answer... the perfect answer.. SVN Export will make your code isolated cleanly from the version control files.



Now situation is so calm. I went to cafeteria with my simple friend. :)

Wednesday, September 15, 2010

.Net MySql Connector

My colleague wasfighting with new Database server and the interesting thing was the server is "MySql",.For us Microsoft people those are little bit odd (we always play with our well structured "MSSQL"). He was actually searching to get a solution to connect to this new DB from his .Net code. Lots of solution tells to install ODBC Driver to connect to MySql.

But I said, no there is something very straight forward like out "System.Data.SqlClient" or "System.Data.OracleClient" namespaces we have, those are available inbuilt with .Net Framework. So for this case I suppose this should be a matter of an assembly reference. And I tried, hardly searched, and atlast Google brought the result.

There is one connection "Mysql-Connector" assembly available in the "Mysql" site itself. From there you can download and as a reference to you project.

http://dev.mysql.com/downloads/connector/net/5.0.html

Now everything as usual, very straight forward . the code goes as like bellow.

//Add reference namespace
using MySql.Data.MySqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//create connection object, command...
MySqlConnection Con = new MySqlConnection();
}
}

So we did it... once again I love .Net :)

Monday, August 30, 2010

Web service cross domain policy

Hm.. Now I hosted my web services for my Silverlight application and everything working fine there in Client server. Meanwhile I just tried to connect the hosted webservice from my development environment(From visual studio project). Nothing unusual, cool.. it throws the error once again to test my patience. It goes like... " This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place "

This time workaround is not in the code its there in the Web service hosted server. In order to enable cross domain policy you have to add a "crossdomain.xml" file in the root of the application host. That is, either in your "wwwroot" or the folder where the root URL points (like if your application hosted in "http://myapplications.com/Webservice1", the cross domain policy xml file you have to locate is "http://myapplications.com/crossdomain.xml". Not inside of any the sub application folders ). Here is the plain simple crossdomain.xml content.

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="SOAPAction,Content-Type"/>
</cross-domain-policy>

This MSDN reference makes it authenticated :)

Thats it!. Simple cool. So enjoy coding :)

Web service project host on remote server

I was moving my project codes to the Remote host server. Actually It's a Silverlight Project and thank god we have Web service support in Silverlight to manage Database stuffs. So I did it well and my client really impressed with my work (Thanks to the magic done by the Silverlight. I really love Silverlight now :) ) So I decided to host it to server from my development environment.

Definitely I've to make sure that my Web service project is working perfectly, because everything depends on that. I hosted it and pulled the URL from my browser. It was nice to see that the web page lists all the WebMethods written to support my application. I clicked one of them to test from there itself that it is pulling data properly and outputs the exact XML. Page moved to the specific function test page to invoke and test the function(Thanks to .Net that we have very nice UI to test the Web service functions.)

But suddenly it shocked me that my "Invoke" button is missing instead it shows "The test form is only available for requests from the local machine". For a moment it made me mad because I've committed the entire application to the client before evening.

But nothing to worry I suppose, as usual google brought the quickest solution. It's just a matter of adding a protocol section in the web.config file. So see bellow it goes like this.

<configuration>
<system.web>
<webservices>
<protocols>
<add name="HttpGet">
<add name="HttpPost">
</add>
</add>
</protocols>
</webservices>
</system.web>
</configuration>

Thats it! now everything fine. Thanks for a cool week start :)

Friday, February 22, 2008

DataKeyNames

One of the Important property of all the Data presentation controls in ASP.Net is the "DataKeynames"

This is available in all of the data controls like GridView, DetailsView....etc. Most of the time we will assign the primary key of the data to this property . We can assign more that one data column value to this field, separated by a comma.This property need to be important at the time of updating a record from the data control.Now we can look one sample on how this datakeyNames were used in a DataGridView

DataKeyNames in GridView

Suppose I want to display an Employee details table data of a company. Here the user don't need to view the employee id in the table.But we were provided a checkbox on each rows corresponding to each employee, and a button provided bellow the Grid. On clicking this button, some action will take place for the checked rows data (here suppose we have to archive the checked row employee's data) . Then Our code will look like as bellow


Employee.aspx

<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
DataKeyNames="emp_id">
<Columns>
<asp:BoundField DataField="fname" HeaderText="First name" SortExpression="fname" />
<asp:BoundField DataField="lname" HeaderText="Last name" SortExpression="lname" />
<asp:BoundField DataField="hire_date" HeaderText="Hire date" SortExpression="hire_date" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [emp_id], [fname], [lname], [hire_date] FROM [employee]">
</asp:SqlDataSource>

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Archive" />
</div>


Employee.aspx.cs

public partial class Employee : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
if (((CheckBox)row.FindControl("CheckBox1")).Checked)
{

int EmployeeID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
//Archive the employee with this employee Id will goes from here
ArchiveEmployee(EmployeeID);

}
}
}
}

Multiple DataKeyNames

Here If we want to to pass more than on field (for example we want to get the DepartmentID) then the the DataKeyNames will write like this

<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
DataKeyNames="emp_id,dept_id">
<Columns>
<asp:BoundField DataField="fname" HeaderText="First name" SortExpression="fname" />
<asp:BoundField DataField="lname" HeaderText="Last name" SortExpression="lname" />
<asp:BoundField DataField="hire_date" HeaderText="Hire date" SortExpression="hire_date" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

And in the Button1_Click event


protected void Button1_Click(object sender, EventArgs e)
{

foreach (GridViewRow row in GridView1.Rows)
{
if (((CheckBox)row.FindControl("CheckBox1")).Checked)
{

int EmployeeID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Values[0]);
int DepartementID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Values[1]);


}
}
}
Updating Data from DetailsView


It is important to set the dataKeyNames, while using ObjectDataSource to bind the details view.Here onclicking the Update button the ObjectDataSource will take Id value from the DataKeyNames of the DetailsView

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataSourceID="ObjectDataSource1" DefaultMode="Edit" DataKeyNames="Id">
<Fields>
<asp:TemplateField HeaderText="first name">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("firstname") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("firstname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="DeleteCustomer"
SelectMethod="GetEmployeeById" TypeName="Employee
UpdateMethod="UpdateEmployee">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="firstname" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>