Aps:button onClick event in Visual web part only fires first time - SharePoint 2013

Below is my markup from ascx file
<asp:Button ID="exporttopdf" runat="server" Text="Export To PDF"/>
C# code for button on click
protected void Page_Load(object sender, EventArgs e)
exporttopdf.Click += new System.EventHandler(this.exporttopdf_Click);
protected void exporttopdf_Click(object sender, EventArgs e)
if (Page.IsPostBack)
try
using (MemoryStream stream = new MemoryStream())
PdfPCell cell;
SPList list = SPContext.Current.Site.OpenWeb().Lists[this.ListName];
BaseColor rGBColor = WebColors.GetRGBColor("#AFAECE");
PdfPTable element = new PdfPTable(2)
TotalWidth = 300f,
LockedWidth = true
float[] relativeWidths = new float[] { 1f, 2f };
element.SetWidths(relativeWidths);
element.HorizontalAlignment = Element.ALIGN_MIDDLE;
element.SpacingBefore = 20f;
element.SpacingAfter = 30f;
if (this.PdfHeading != null)
cell = new PdfPCell(new Phrase(this.PdfHeading));
else
cell = new PdfPCell(new Phrase(this.ListName));
cell.Colspan = 2;
cell.Border = 0;
cell.Padding = 4;
cell.BackgroundColor = rGBColor;
cell.HorizontalAlignment = 1;
element.AddCell(cell);
Document document = new Document(PageSize.A4, 25f, 25f, 30f, 30f);
PdfWriter instance = PdfWriter.GetInstance(document, stream);
document.Open();
document.AddAuthor("Place Holder");
document.AddCreator("Place Holder");
document.AddKeywords("Place Holder");
document.AddSubject(this.ListName);
document.AddTitle(this.ListName);
instance.Info.Put(new PdfName("Producer"), new PdfString("Place Holder"));
PdfContentByte directContent = instance.DirectContent;
string[] separator = new string[] { ";", "," };
string[] strArray2 = this.ViewFields.Split(separator, StringSplitOptions.None);
new StringBuilder().Append(this.ListName + "\n");
foreach (string str in strArray2)
PdfPCell cell2 = new PdfPCell(new Phrase(str))
Border = 0,
Padding = 4,
HorizontalAlignment = 1
element.AddCell(cell2);
if (str != "Modified By" && str != "Created By")
PdfPCell cell3 = new PdfPCell(new Phrase(SPContext.Current.Item[str].ToString()))
Border = 0,
Padding = 4,
HorizontalAlignment = 1
element.AddCell(cell3);
else
string[] separatorc = new string[] { "," };
string[] strArray3 = SPContext.Current.Item[str].ToString().Split(separatorc, StringSplitOptions.None);
PdfPCell cell3 = new PdfPCell(new Phrase(strArray3[3].ToString().Substring(8).Replace(@"\\", @"\")))
Border = 0,
Padding = 4,
HorizontalAlignment = 1
element.AddCell(cell3);
PdfPCell cell4 = new PdfPCell(new Phrase("Footer"))
Colspan = 2,
Border = 0,
Padding = 4,
BackgroundColor = rGBColor,
HorizontalAlignment = 1
element.AddCell(cell4);
document.Add(element);
document.Close();
instance.Close();
stream.Close();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "pdf/application";
string filename = SPContext.Current.Item["Title"].ToString() + ".pdf";
HttpContext.Current.Response.AddHeader("content-disposition", "inline;filename=" + filename);
HttpContext.Current.Response.OutputStream.Write(stream.GetBuffer(), 0, stream.GetBuffer().Length);
HttpContext.Current.Response.End();
catch (Exception exception)
SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("Export To PDF", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, exception.Message, new object[] { exception.StackTrace });
else
HttpContext.Current.Response.Write("<script language=javascript>alert('ERROR');</script>");
it works fine first time but does not do anything from second.
any advice?

Hi,
Please try to the code snippet as below:
VisualWebPart1.ascx:
<asp:Button ID="exporttopdf" runat="server" Text="Export To PDF" OnClick="exporttopdf_Click"/>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
VisualWebPart1.ascx.cs:
protected void Page_Load(object sender, EventArgs e)
protected void exporttopdf_Click(object sender, EventArgs e)
Label1.Text = System.DateTime.Now.ToString();
If the code still do not work from second, I suggest you debug your code and check whick line of code occur the error.
More information:
http://social.msdn.microsoft.com/Forums/office/en-US/94931a08-f204-4d30-a230-f468815a76e8/export-aspnet-gridview-to-pdf-from-visual-webpart?forum=sharepointdevelopmentprevious
Thanks,
Dennis Guo
TechNet Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Dennis Guo
TechNet Community Support

Similar Messages

  • HOW TO CALL APPROVAL WORK FLOW ON BUTTON CLICK EVENT OF VISUAL WEB PART?

    Hiall,
    I created an OOB an approval work flow I want to start that approval work flow through visual web  part button click event
    In work flow Settings I selected to manually start .Is this possible ? if possible please guide me how to do this
    Thanking you,
    Arun  kumar

    Hi,
    If you have an instance of SPListItem, and know the workflow association name, you can start it. First you need to find workflow assocation instance and tell SPSite.SPWorkflowManager to start your workflow.
    See this for more information:
    http://blog.mmasood.com/2012/06/programatically-start-workflow.html
    Please remember to up-vote or mark the reply as answer if you find it helpful.

  • Target Audience web part property is missing in sharepoint 2013

    Dear All,
                 The "Target Audience" web part property is missing in SharePoint 2013. But this was a feature in SharePoint 2007. Is there any other way of doing this in SharePoint 2013
    Thanks,
    Dilip

    Hi,
    Here are the reasons & solutions for SharePoint 2010 audience targeting missing: 
    1. Enable audience targeting in SharePoint 2010 Site Collection
    Go to Site Actions >> Site Setting >> Click on "Site collection navigation" >> under Site Collection
    Administration >> Make sure "Enable Audience targeting" is checked. 
    2. Audience Targeting feature is depending on SharePoint Publishing feature. So, Go to Site Settings >>
    Site collection features >> SharePoint Server Publishing Infrastructure” Activate publishing feature on your site collection.
    3. For Audience Targeting, We need "User Profile Service Application"! So make sure the user profile
    service application is provisioned and running. Check the status of "User Profile Service" and "User Profile Synchronization Service" . Verify the UPSA is associated with your Web Application, by going to:
    Central Administration >> Application Management 
    Manage Web Applications >> Highlight Your Web Application 
    Service Connections >> Make sure User Profile Service Application is checked.
    Restart IIS!
    Read more: http://www.sharepointdiary.com/2013/05/audience-targeting-missing-in-sharepoint.html#ixzz3O2aRr0lJ
    Hope
    it helps!
    Thanks,
    Avni Bhatt
    If this helped you resolve your issue, please mark it Answered

  • How to redirect to library on button click in sandbox visual web part solution for office 365

    Hi,
    I have created a sandbox solution for Office 365 with one text box and a button. 
    On button click i am creating a library with name from text box. 
    So, what i want is redirect to newly created library as soon it get created on button click.
    how could i do that?
    Thanks

    Got the solution
    <asp:Literal ID="litRedirect" runat="server" />
    string redirectURL =
    listurl;
    litRedirect.Text = "<script type='text/javascript'>window.location = '" +
    redirectURL + "/';</script>";

  • How to Add a User Control to a SharePoint 2013 Visual Web Part ?

    Hi,
    1.I have created SharePoint 2013 Farm Solution through VS 2012.
    2.Added visual Web part
    3.Created a User control (Farm Solution ) and added some Control From tool Box.
    4.Drag and drop user control from solution explorer to visual web part.
    so its  Register tag and with prefix tag user controls automatically added on visual web part source. when i try to build solution it throws Exception:
    Exception :The name 'InitializeControl' does not exist in the current context.
    Please Provide solution after try/or proper workaround.
    Thanks,
    Siddheshwar

    Site name=http://sitename:22222/
    Visual Web part:
    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Src="~/_controltemplates/15/SP2013Controls/SPControls.ascx" TagPrefix="uc1" TagName="SPControls" %>
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SPWebpart.ascx.cs" Inherits="SP2013Controls.SPWebpart.SPWebpart" %>
    <uc1:SPControls runat="server" id="SPControls" />
    User Control Code:
    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SPControls.ascx.cs" Inherits="SP2013Controls.ControlTemplates.SP2013Controls.SPControls" %>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server" Text="Button" />
    Deployement Location:{SharePointRoot}\Template\ControlTemplates\SP2013Controls\
    After User controls added on webpart .g.cs file getting blank.
    After 1st Build:
    'InitializeControl' does not exist in the current context
    The file '/_controltemplates/15/SP2013Controls/SPControls.ascx' does not exist.
    after 2nd Build Try:
    'InitializeControl' does not exist in the current context

  • How to display alert message box in sharepoint 2013 visual web part?

    Hi,
    I am developing a visual web part which submits data to the list. Once it submits the data, I should convey to the user that the data has been submitted successfully.
    I tried using clientScript.RegisterStartUpScript etc, but, none of them are working. It is not throwing any error , but pop up is not getting displayed.
    Preferrably, I would like to call this alert message from cs page, because, I will be using it in several places.
    Please help me.!
    Thanks in advance.
    Hepsi

    Hepsi, 
    Step 1. On the Page_Load - This way you can pass parameters. Try this
    btn.Attributes.Add(
    "onclick", string.Format("return openSPPopup('{0}?{1}={2}', '{3}')", YourPage_URL, var1_Name, value1, Param1_PopupTitle));
    Step 2 : Javascript function
    function openSPPopup(navigateURL, popUptitle) {
    var options = {
    width: popupWidth,
    height: popupHeight,
    url: navigateURL,
    scroll: 0
    SP.UI.ModalDialog.showModalDialog(options);
    return false;
    Step 3: The popup close code (in .cs file) – I do it this way as it is just close dialog code and easy to write.
    protected void btnClose_Click(object sender, EventArgs e)
    { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "SP.UI.ModalDialog.commonModalDialogClose(1, 1);", true);
    Courtesy -
    Thread
    Try this - https://bramdejager.wordpress.com/2011/03/21/using-sp-ui-dialog-and-sp-ui-notify-from-code-behind/
    http://msdn.microsoft.com/en-us/library/ff798390.aspx
    http://stackoverflow.com/questions/9833907/asp-net-confirm-before-executing-codebehind
    http://www.codeproject.com/Questions/443131/Call-to-javascript-Function-from-code-behind-using
    http://www.c-sharpcorner.com/uploadfile/ledomoon/calling-code-behind-function-in-javascript/
    Hope they will help!
    Please 'propose as answer' if it helped you, also 'vote helpful' if you like this reply.

  • Create a Site Definition file with Visual Web part in Visual Studio

    I tried to create a site definition file in Visual Studio 2013 and SharePoint 2013 by following the MSDN tutorial:
    Walkthrough: Create a Basic Site Definition Project. Near the end, I added a virtual web part control to the site definition and registered MyWebPartControls in the site definition's default ASPX page as written in the MSDN tutorial:
    Unfortunately, IntelliSense doesn't show any MyWebPartControls: tags, and VisualWebPart1 is highlighted with a warning “Element 'SMWebPart3' is not a known element. This can
    occur if there is a compilation error in the Web site, or the web.config file is missing.”
    Since it’s a warning, I went ahead to build and deploy the solution. However, when I used the site definition template to create a subsite, it returned a parser error:
    Unknown server tag 'MyWebPartControls:TestSiteDef1.VisualWebPart1'
    I spent half day researching and debugging, and finally solved the problem. The issue is on the registration line:
    <%@ Register Tagprefix="MyWebPartControls" Namespace="TestSiteDef.VisualWebPart1" Assembly="$SharePoint.Project.AssemblyFullName$" %>
    The $SharePoint.Project.AssemblyFullName$ is a replaceable parameter to provide values for SharePoint solution items whose actual values are not known at design time. Unfortunately, it does not find the right assembly name during the deployment. It should
    be replaced by the Assembly’s Strong Name. Here is how I fixed the problem step by step:
    In Solution Explorer, open the package node and double click Package.package
    Click Manifest tab in the Package.package.
    Copy the full assembly name in the package’s manifest. It may be similar like this:
              Assembly="TestSiteDef,
    Version=1.0.0.0, Culture=neutral, PublicKeyToken=a300f1f2da8ae976"
    Back to the site definition’s default.aspx page, replace the
                     Assembly="$SharePoint.Project.AssemblyFullName"
    in the registration line with the copied text:
    Assembly="TestSiteDef,
    Version=1.0.0.0, Culture=neutral, PublicKeyToken=a300f1f2da8ae976"
    Change the Namespace from
    Namespace="TestSiteDef.VisualWebPart1"
    to
    Namespace="TestSiteDef".
    The line to register the web part in a site definition file will look like this:
    <%@
    Register
    Tagprefix="MyWebPartControls"
    Namespace="TestSiteDef "
    Assembly="TestSiteDef, Version=1.0.0.0,
    Culture=neutral, PublicKeyToken=a300f1f2da8ae976"
    %>
    Clean, build and deploy the solution. It works like charm. (Note: the warning message on visual web part may still exist, but you can ignore it).

    Assuming your .ascx.vb file is inheriting from the web part class, you can add the custom properties in the same manor (language syntax aside).
    Be sure to use the attributes to correctly identify and scope the properties. (see:
    http://www.sbrickey.com/Tech/Blog/Post/SharePoint_Attributes_for_Web_Part_properties)
    Scott Brickey
    MCTS, MCPD, MCITP
    www.sbrickey.com

  • Create a visual web part which get data from excel sheet and import it into sql server database in sharepoint 2010 (development)

    Hi,
    I want to create a visual webpart which will read data from excel sheet and import it in to sql server database.(using sharepoint development)
    I want to do it using visual webpart.
    Please help to solve the issue.
    Thanks in advance!
    Regards
    Rajni

    Hi  Rajni,
    Microsoft.Office.Interop.Excel assembly provides class to read excel file data, in your web part solution, reference the assembly, and following blog contains samples about how to read the excel file data,
    and import it to SQL  database.
    1.Create a Visual Web Part Project:Create
    Visual Web Parts in SharePoint 2010
    2.Read the excel workbook by using SPFile class:
    http://alancejacob.blogspot.in/2012/06/read-data-from-excel-file-and-insert-in.html
    http://stackoverflow.com/questions/14496608/read-excel-file-stored-in-sharepoint-document-library
    3.Export the excel workbook to SQL Server:
    http://www.c-sharpcorner.com/UploadFile/99bb20/import-excel-data-to-sql-server-in-Asp-Net/
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • Access denied error while adding visual web part

    i am trying to create visual web part using client side code in SharePoint 2013.
    i am able to deploy my web part but when I try to add it on a page it says " Access denied. You do not have permission to perform this action or access this resource" and when i try to debug it it shows exception: "The remote server returned
    an error: (500) Internal Server Error."
    Following is the code:
     protected void Page_Load(object sender, EventArgs e)
                var ClientContext = new ClientContext("http://172.20.30.100:1111/");
                        //SP.ClientContext.get_current();
                Web web = ClientContext.Web;
                ClientContext.Load<Web>(web);
                ClientContext.ExecuteQuery();
                var BU = web.Title;
                ListCollection ListColl = web.Lists;
                List list = ListColl.GetByTitle("LNT_Testimonial");
                CamlQuery CmlQry = new CamlQuery();
                CmlQry.ViewXml = @"<View>
                                        <Query>
                                          <Where>
                                            <Eq>
                                              <FieldRef Name='BU' />
                                              <Value Type='Text'>" + BU + @"</Value>
                                            </Eq>
                                          </Where>
                                        </Query>
                                        <RowLimit>1</RowLimit>
                                      </View>";
                Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(CmlQry);
                ClientContext.Load<ListCollection>(ListColl);
                ClientContext.Load<List>(list);
                ClientContext.Load<Microsoft.SharePoint.Client.ListItemCollection>(items);
                ClientContext.ExecuteQuery();
                //var testimonial = items.FieldValues["testimonial"];
                foreach (Microsoft.SharePoint.Client.ListItem item in items)
                    var testimonial = item.FieldValues["testimonial"];
    regards, Ritesh Anand

    I'm not sure if you are trying to create visual webpart or doing something else? As I understand from your code, maybe, you are trying to access list item. If you have access to the server (on-premise), you can check the ULS log for details of the error.
    Is it access denied or 'internal server errror'. If it's internal server error then more details can be found in SharePoint ULS log. About reporting service, not sure if it's related to your original question. Please try to use a single post to focus on single
    problem.
    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com

  • Way to use Visual Web part in sharepoint 2010 without using/installing third party tools

    I want to know the way to use Visual Web part in sharepoint 2010 without using/installing third party tools.
    Please provide me a link where i can actually know how it is done.

    + to _eNo_,
    Visual Studio 2010 has support for visual webpart, you can find that under Visual C# node in the Installed Templates section (if your preferred language is C#)
    Hope this helps!
    Ram - SharePoint Architect
    Blog - SharePointDeveloper.in
    Please vote or mark your question answered, if my reply helps you

  • Returning Name and Username from People Picker Field in Visual Web Part

    Dear All
    I am creating a visual web part that displays a list that I have created in SharePoint. One of the fields in the list is a People & Groups column type (People Picker) called 'Presented by'. In my web part, I would like to display the username and
    the name of the person who has been 'picked' in this field. However, my using <%# Eval("Presented by") %> only displays their name. How do I get this field to also return their username?
    Many thanks for your help
    Daniel

    You ca  use this code:- change it according to your need
    int requestForUserID = 0;
    string requestForUserLoginName = string.Empty;
    string requestForUserName = string.Empty;
    string userAccount = peoplePickerEmployee.CommaSeparatedAccounts;
    string[] UsersSeperated = peEmployeeOnBehalf.CommaSeparatedAccounts.Split(',');
    foreach (string user in UsersSeperated)
    SPContext.Current.Web.EnsureUser(user);
    SPUser spUser = SPContext.Current.Web.SiteUsers[user];
    requestForUserID = spUser.ID;
    requestForUserLoginName = spUser.LoginName;
    requestForUserName = spUser.Name;
    Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
    INSQLSERVER.COM
    Mohammad Nizamuddin

  • How to create Auto complete text box in share point 2010 Visual web part

    Hi All ,
    I am want to use Auto complete text box in share point 2010 Visual web part ,data need to get from share point list how to  create 
    please guide me how to use Auto complete text box
    Thanking you,
    Arun Darly

    Hi Arun,
    Please refer to the following article.
    SharePoint 2010: JQuery Autocomplete Textbox Containing List Items
    http://smarttools.codeplex.com/wikipage?title=Autocomplete%20Text%20Field
    Please don't forget to mark it as answered, if your problem resolved or helpful.

  • Connectable Visual Web Parts

    Hi..
    how to use Connectable Visual Web Parts in 2 different pages.
    Ravindranath

    The old SharePoint framework has a framework for that, cross/page web part connections:
    http://msdn.microsoft.com/en-us/library/dd585662(v=office.11).aspx I'm not entirely sure if you still can create those kind of web parts in 2010 and you'll have to find that out,
    but the new web part connections framework doesn't support cross-page connections.
    Kind regards,
    Margriet Bruggeman
    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com

  • Visual Web Part Value not Selecting in Page Redirection

     Hi..
     I have a Visual Web Part having DropDown Controls and adding Webpart in 3 Web Part Pages .. When we redirect from 1 page to another, the  selected dropdown values are not coming in 2nd and 3rd page..
    Ravindranath

    You have added visual web part in three different pages, drop down value will not be selected when you redirect to page 2 or page 3 because they are separate pages and a separate web parts added on each page. Each page has a separate page life cycle.
    You can only set dropdown value by passing query string parameter.
    Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer.

  • SharePoint visual web part project creation usng TFS2010

    Hi,
    I have configured TFS2010 in SharePoint 2010 server and used TFS url in client machine.
    From client machine i am able to create new TFS project, but i cannot find information's to create SharePoint project using VS2010 SharePoint templates?
    How to create Visual web part project using TFS2010?
    Anandhan.S Remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    Hi,
    According to your post, my understanding is that you wanted to create SharePoint project using the TFS 2010.
    Did you install the Build Support for Apps for Office and Apps for SharePoint?
    To build apps for Office and apps for SharePoint projects, several components must be installed on your system.
    What’s more, we should copy several Visual Studio SharePoint assemblies to the GAC on the build server.
    Copy the SharePoint Tool Assemblies and Files to the GAC
    The following assemblies must be copied to the GAC of the build system:
    Microsoft.VisualStudio.SharePoint.Designers.Models.dll
    Microsoft.VisualStudio.SharePoint.Designers.Models.Features.dll
    Microsoft.VisualStudio.SharePoint.Designers.Models.Packages.dll      Microsoft.VisualStudio.SharePoint.dll
    There are two articles about building SharePoint 2010 solutions on TFS 2010, I think it’s helpful for your to create project in TFS2010.
    http://msdn.microsoft.com/en-us/library/ff622991.aspx
    http://blogs.msdn.com/b/jjameson/archive/2011/02/27/building-sharepoint-2010-solutions-on-a-tfs-2010-build-server.aspx
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

Maybe you are looking for