Sunday, April 7, 2013

Setting up Github with Visual Studio 2012

This is a step by step tutorial on setting up your github repository with Visual Studio 2012

Step 1.) Install Visual Studio 2012 Update 2

Step 2.)Go to Tools >> Extensions and Updates
 - Install "Git Source Control Provider" and "Visual Studio Tools for Git"
Step 3.) Open up View >> Team Explorer
   - Click the plugin icon.
   - Select the "Clone" link under Local Git Repositories
   - Add you github repository url.
   - Press Clone and you will be prompted for your username and password

Hope this helps everyone out.


Wednesday, June 27, 2012

Formatting data using Html.TextBoxFor asp.net MVC

If you've ever wanted to format values such as decimal or dates using the TextBoxFor helper, here's how.




@Html.TextBoxFor(m => m.YourProperty, new { @class = "MyClass", @Value = string.Format("{0:C}",Model.YourProperty) })




You can do this using EditorFor and the DisplayFormat annotation.  However, you loose the ability to add class to your textbox.

Wednesday, April 4, 2012

Enable Remote Connections on Sql Server

SQL Configuration Manager

Run SQL Server Configuration Manager.
SQL Configuration Manager
Expand SQL Server 2005 Network Configuration node.
Click Protocols for SQL Express.
Double click TCP/IP. Dialog TCPI/Properties will appear.
Set Enabled=Yes. Click IP Address tab.

Set Active = Yes. Set Enabled = Yes.

Client Protocols

Expand SQL Native Client Configuration. Double click TCP/IP to display TCP/IP Properties.
Set Default Port = 1433, Enabled = Yes.
Now is access to SQL Server by TCP/IP enabled.
Next step is to enable Remote Connections.

How to enable remote connections

Run SQL Server Surface Area Configuration.
Click Surface Area Configuration for Services and Connections.
In screen that will appear expand your server, Database Engine, Remote Connections.
Click Local and remote connections.
Choose Using both TCP/IP and named pipes.

Firewall settings

SQL Server requires enabled TCP and UDP ports. Run Windows Firewall from Control Panel.
Display Exceptions tab.
Click Add port button. Dialog Add a Port will appear.
Enter:
  • Name = MSSQL tcp
  • Port nuber = 1433
  • TCP
Repeat these steps to add UDP port with values:
  • Name = MSSQL ucp
  • Port nuber = 1434
  • UDP

Thursday, October 27, 2011

Cannot implicitly convert type 'System.Data.Objects.ObjectResult' to 'int?'

When you're executing a Save on your DataContext using EF, and get this error:

Cannot implicitly convert type 'System.Data.Objects.ObjectResult' to 'int?'

You may want to try adding a SingleOrDefault or FirstOrDefault to the end of your SPROC call to close the transaction before you save.

BAD
int? rc = myContext.myProc(myParameter);
myContext.Save();

GOOD
int? rc = myContext.myProc(myParameter).FirstOrDefault();
myContext.Save();

Sunday, November 15, 2009

Text Wrap in GridViews

If you want to make your text wrap in a GridView control, just add the style WORD-BREAK:BREAK-ALL.
protected void gridViewCustomer_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("style", "WORD-BREAK:BREAK-ALL");
}
{

Friday, November 13, 2009

Read XML doc with xmlns using XDocument

Sample Xml File County.xml

<root xmlns="nameSpace">
<county>
<group name="Sutter">
<group name="Yuba">
<group name="Placer">
</group>
</group>
<root>

-----------------------------------------------------------

//C#
XDocument xDoc = XDocument.Load("Country.xml");
XNamespace ns = xDoc.Root.Name.Namespace;

//adding the namespace infront of the XName will allow you to access the node.
var elements = xDoc..Element(ns+"root").Element(ns+"County").Descendants(ns+"Group");

foreach (var element in elements)
{
Console.Write(element.Attribute("name").ToString());
}




Tuesday, September 22, 2009

siteMapNode target="_blank"

Don't waste your time adding a target="_blank" attribute in your sitemapNode, IT DOESN'T WORK. There is a work around though. Add JavaScript to open your link in a new page.

Example:
(Will not work)<sitemapnode url="http://www.google.com" title="Google" target="_blank">

(WORKS!)<sitemapnode href="javascript:var w=window.open('http://www.google.com','google');" title="Google" />