Wednesday, April 25, 2012

Setting Up a Team Foundation Server 2010 Project

Reference : http://msmvps.com/blogs/bmains/archive/2010/05/01/setting-up-a-team-foundation-server-2010-project.aspx

I recently installed TFS 2010 and began to setup my projects, so I decided to create this blog post. I’m not going to cover the installation aspect of TFS; rather, I’m going to assume that you successfully installed the base software; this blog doesn’t discuss the use of the proxy or the build service either, just the TFS product and Sharepoint Services 3.0. If you have a SharePoint server, this is supported; however, there are a few more setup procedures available online. To begin, let’s open up Visual Studio 2010, open the project, and open up the Team Explorer tool window on the right. Click the far right icon of the toolbar, Connect to Team Project.


If you have made a connection previously, that entry appears in the “Team Project Collections” list; if you don’t have your target TFS specified, click the Servers button.


On the Add/Remove Server screen, click add, and specify the server to add. Either type in the server name directly, or enter in the full URL. If you type in the server name, specify the path and port in the respective textboxes.



Clicking OK will add the entry to the list. Click close on the Add/Remove TFS screen. In the previous screen (Connect to Team Project), select the newly added server and click Connect. You are connected to the server.

A TFS admin may have to setup a collection for your project; by default, the DefaultCollection is the only collection projects can be added to; having a separate collection means that project can be backed up and restored independently of other projects. These collections setup on the server are what you see in the team explorer. Right click one of the collections, and select New Team Project:


In the opening screen, enter the name and description of the project.



Click next when finished. The next screen asks for the template you would like to use for the project.





Click next to configure the Sharepoint portal site. Team Foundation Server is integrated with SharePoint and installs SharePoint Services 3.0 if you do not have the full SharePoint server installation. By default, if follows a <server>/sites/<collection name>/<project> folder structure. Click configure to change some of the SharePoint settings.

Note: if you don’t have permissions, you may not be able to create the SharePoint site. The SharePoint site can be created manually and linked to the project after installation. If you don’t have permissions, select “Do not configure a SharePoint site at this time”.



Next, specify the location for the project, or branch it from another project.


Finally, view the final statistics and ensure that the project is setup correctly.



This communicates with the server and setups the following project structure within the Team Explorer:




Now our team system project is setup. The following items in this list are:

Work Items – A place to add work items, assign them to members of the team, and so on. Use team queries to get a predefined query of work items, or create your own queries in the “My Queries” option.

Documents – A document library location for you to store documents related to the project.

Reports – Any reports for the project setup in Reporting Services by the installation.

Builds – Any builds defined by the build service for the project.

Source Control – Visit this feature to add your projects to the source control database for the first time.

Reference : http://msmvps.com/blogs/bmains/archive/2010/05/01/setting-up-a-team-foundation-server-2010-project.aspx

Thursday, April 12, 2012

Why don't file uploads work during async postbacks?

Full Reference : http://weblogs.asp.net/leftslipper/archive/2007/03/30/why-don-t-file-uploads-work-during-async-postbacks.aspx

As many people have noticed in their AJAX-enabled pages, file uploads do not work when doing an async postback. To my knowledge there's no way to support this scenario due to the browser's security restrictions. To understand why the upload doesn't work it's important to understand how async postbacks are performed and how that's different from how the browser performs a regular postback.

When the browser performs a regular postback it has the benefit of being actual code with no security restrictions running on the client computer. When you submit a form it creates a web request with all the form fields. When it encounters an <input type="file"> it examines the file the user chose, reads it from disk, and adds it to the web request.

When the AJAX JavaScript code is running in the browser it can do the first part about creating a request with all the form fields. However, when it gets to <input type="file"> fields it doesn't have the necessary security permissions to read those files from disk. Imagine what would happen it it could read those files: You could create a page that when visited will upload the user's c:\passwords.txt to a remote server! And we all know that every user has a file called passwords.txt on their C: drive. I bet just now you renamed it so my evil code couldn't run :)

So what's the workaround? Well, quite simply, the workaround is to do anything that doesn't involve a file upload during an async postback. Here are some solutions:

  1. Have a dedicated "Upload" button that does a regular postback instead of an async postback. You can achieve this using several techniques: Have the button be outside all UpdatePanels; have the button be the target of an UpdatePanel's PostBackTrigger; or call ScriptManager.RegisterPostBackControl() on it.
  2. Have a dedicated file upload page that doesn't have any UpdatePanels. Many web sites already do this anyway.

And now you might wonder, "why don't ASP.NET AJAX and the UpdatePanel handle this better?" We did give this a fair bit of thought and we decided that doing nothing was the best solution. One option we had was to throw some error from JavaScript if we detected any filled out <input type="file"> tags. But what if you wanted to do an async postback that had nothing to do with the file upload? Or perhaps only detect file uploads in certain regions of the document? That would involve even more expensive DOM tree walks that are already causing some performance degradation with UpdatePanels.

In conclusion, if you want a secure browser, you're not going to get file upload functionality from UpdatePanels. If you don't want a secure browser, please get your head checked. If you want to do file uploads, just use one of the two solutions I provided.

Tuesday, April 3, 2012

Check/Uncheck checkboxes in GridView using JavaScript

Reference :- http://wiki.asp.net/page.aspx/281/check-uncheck-checkboxes-in-gridview-using-javascript/

The question regarding how to check/uncheck CheckBoxes within a GridView control using JavaScript has been asked many times. Here is a quick reference you can follow.

First we have the .aspx markup.

<script type="text/javascript">
function SelectAll(id) {
var frm = document.forms[0];
for (i=0;i<frm.elements.length;i++) {
if (frm.elements[i].type == "checkbox") {
frm.elements[i].checked = document.getElementById(id).checked;
}
}
}
</script>
<!-- assuming that SqlDataSource1 is the datasource for my GridView -->
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" Width="400px">
<Columns>
<asp:TemplateField>
<AlternatingItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</AlternatingItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="cbSelectAll" runat="server" Text="Select All" />
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
</Columns>
</asp:GridView>

Next we have the code-behind in both VB and C#

VB

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.Header) Then
'adding an attribute for onclick event on the check box in the header
'and passing the ClientID of the Select All checkbox
DirectCast(e.Row.FindControl("cbSelectAll"), CheckBox).Attributes.Add("onclick", "javascript:SelectAll('" & _
DirectCast(e.Row.FindControl("cbSelectAll"), CheckBox).ClientID & "')")
End If
End Sub

C#

protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.Header) {
//adding an attribute for onclick event on the check box in the header
//and passing the ClientID of the Select All checkbox
((CheckBox)e.Row.FindControl("cbSelectAll")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)e.Row.FindControl("cbSelectAll")).ClientID + "')");
}
}

The example above is fantastic, but there are a couple things that could be improved.

  1. The JavaScript Pseudo Protocol (Javascript:your method here) should be avoided, it's a fragment from the old Netscape days. Today there are better alternatives
  2. In this case we probably don't need the server-side portion altogether.

An excerpt about the JavaScript Pseudo Protocol:

"The javascript: pseudo-protocol should not be used in event handlers like onclick. It should only be used in attributes that contain a URL, for example in the href attribute of <a> elements and the action attribute of <form> elements. You can also use it to make bookmarlets." - Common JavaScript Mistakes

Another solution the .aspx markup:

<script type="text/javascript">
// Let's use a lowercase function name to keep with JavaScript conventions
function selectAll(invoker) {
// Since ASP.NET checkboxes are really HTML input elements
// let's get all the inputs
var inputElements = document.getElementsByTagName('input');
for (var i = 0 ; i < inputElements.length ; i++) {
var myElement = inputElements[i];
// Filter through the input types looking for checkboxes
if (myElement.type === "checkbox") {
// Use the invoker (our calling element) as the reference
// for our checkbox status

myElement.checked = invoker.checked;
}
}
}
</script>
<!-- assuming that SqlDataSource1 is the datasource for my GridView -->
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField>
<AlternatingItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</AlternatingItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="cbSelectAll" runat="server" Text="Select All" OnClick="selectAll(this)" />
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
</Columns>
</asp:GridView>