SELECT DISTINCT [Groups].[Title] as 'Group', [UserInfo].[tp_Title] as 'User', [UserInfo].[tp_Email] as 'Email' FROM [Groups] INNER JOIN [GroupMembership] ON [GroupMembership].GroupId = [Groups].ID AND [GroupMembership].SiteID = [Groups].SiteID INNER JOIN [UserInfo] ON [UserInfo].tp_ID = [GroupMembership].MemberId AND [UserInfo].tp_SiteID = [GroupMembership].SiteID ORDER BY [Groups].[Title] ASC, [UserInfo].[tp_Title] ASCBy the way, please don't get the impression that I'm implying that you can write INSERT or DELETE statements against these databases. The minute you do that is the minute that Microsoft will "disown" your SharePoint site and will not be able to provide technical support for it. This information should be considered READ-ONLY to you and you should only add, modify, or delete users using the SharePoint interface.
Tuesday, April 17, 2012
Obtaining a List of Users from a SharePoint site via a SQL command
It's only a matter of time before your PM is going to come to you one day and ask you "so...who now has access to that site you set up about a year ago?". Rather than having to root around the various groups and compiling the list by hand, the quick n' dirty solution to this problem is to run the following SQL command against your SharePoint content database. This query will quickly obtain a list of users based on the SharePoint groups they belong which you can then slap it into an Excel spreadsheet for them:
Friday, April 13, 2012
Programmatically initiate javascript from code behind
Occassionally, situations may arise in which you want to initiate javascript from the C# code behind of your web application. In the following simple example, the code in the Page Load event is triggering a simple alert message to fire; however, the sky is the limit with all the possibilities that this opens up:
Enjoy!
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!ClientScript.IsStartupScriptRegistered(this.GetType(),"alert")) { Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('All leases must be re-assigned to another parent before the delete operation may continue. You may use this view to re-assign those leases.');", true); } } }
Enjoy!
Tuesday, April 10, 2012
Launch a javascript alert or confirmation from a button located within a GridView control
I recently ran into a situation in which the business owner wanted to add a javascript popup that would confirm that the user did indeed wish to delete the selected row from a given GridView. Originally, I was using a standard ButtonField control to display the delete button in the GridView which I've presented as follows:
but, decided to switch gears and use the following code instead to incorporate that javascript popup:
The good news is that this new solution will work exactly like the previous ButtonField control with regards to your GridView_RowCommand event so you won't have to change any of your code in that event. This is due to the additional CommandArgument attribute that you see in the Button control that will pass the selected row index in similar fashion to what takes place automatically with the previous ButtonField control.
In the event that you'd prefer to use a javascript alert instead of a confirmation, here's some sample code for that as well...
<asp:ButtonField CommandName="DeleteRecord" ControlStyle-Height="23px" ControlStyle-Width="75px" ControlStyle-CssClass="GridView_Delete_Button" />
but, decided to switch gears and use the following code instead to incorporate that javascript popup:
<asp:TemplateField> <ItemTemplate> <asp:Button ID="btnDeleteParentCode" runat="server" ControlStyle-Height="23px" ControlStyle-Width="75px" ControlStyle-CssClass="GridView_Delete_Button" CommandName="DeleteRecord" CommandArgument="<%# Container.DataItemIndex %>" OnClientClick="return confirm('Are you certain you wish to delete the selected record');" /> </ItemTemplate> </asp:TemplateField>
The good news is that this new solution will work exactly like the previous ButtonField control with regards to your GridView_RowCommand event so you won't have to change any of your code in that event. This is due to the additional CommandArgument attribute that you see in the Button control that will pass the selected row index in similar fashion to what takes place automatically with the previous ButtonField control.
In the event that you'd prefer to use a javascript alert instead of a confirmation, here's some sample code for that as well...
<asp:TemplateField> <ItemTemplate> <asp:Button ID="btnMove" runat="server" ControlStyle-Height="23px" ControlStyle-Width="75px" ControlStyle-CssClass="GridView_Move_Button" CommandName="Move" CommandArgument="<%# Container.DataItemIndex %>" OnClientClick="return alert('The record you've selected has been moved to a new location');" /> </ItemTemplate> </asp:TemplateField>
Wednesday, March 14, 2012
Export the contents of a GridView to an Office 2007 Excel file
One of our testers recently asked me if there was a quick way to export the contents of a GridView control to an Office 2007 Excel output file. After a bit of research, I was able to put together a functional solution that works, but is something that I'd be hesitant to use in a Production environment. Perhaps this may inspire you to find a more optimal solution, but here is the quick solution that actually works:
First, you will need to add a button control to the aspx page on which the GridView is hosted as follows:
Next, you will need to add the following C# code to the aspx.cs file that is initiated by the button onclick event:
Once you've updated your data source, you can fire up your web app and test the process of exporting the .xls document by clicking on the Export to Excel button. NOTE: That first IF statement you see in this code verifies that data is actually being displayed in the GridView that is exposed to the user on the web page.
First, you will need to add a button control to the aspx page on which the GridView is hosted as follows:
<asp:Button runat="server" ID="btnExportToExcel" Text="Export to Excel" onclick="btnExportToExcel_Click" />
Next, you will need to add the following C# code to the aspx.cs file that is initiated by the button onclick event:
protected void btnExportToExcel_Click(object sender, EventArgs e) { if (GridViewDisplay.Rows.Count > 0) { string outputFileName = "GetActivePropertiesByMarket.xls"; // Prep the Response object to return the data as a file/attachment Response.Clear(); Response.Charset = string.Empty; Response.AddHeader("content-disposition", string.Format("attachment;filename={0}", outputFileName)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = outputFileName; // Obtain the data from the data source // NOTE: For the purposes of this example, I'm referencing a web method; however, you will probably use another means... ePM_New.YardiPropertySearchWS service = new ePM_New.YardiPropertySearchWS(); DataSet ds = service.GetActivePropertiesByMarket(market); DataView dv = new DataView(ds.Tables[0]); // Bind the data to a second GridView that will be written to the output file... GridView grid = new GridView(); grid.DataSource = dv; grid.DataBind(); // Establish a means of writing the contents of the GridView to the output file System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(sw); grid.RenderControl(htmlWriter); Response.Write(sw.ToString()); Response.End(); } }
Once you've updated your data source, you can fire up your web app and test the process of exporting the .xls document by clicking on the Export to Excel button. NOTE: That first IF statement you see in this code verifies that data is actually being displayed in the GridView that is exposed to the user on the web page.
Tuesday, March 13, 2012
Remove the "Add as Colleague" link from a My Site
Here is a simple trick that you can use to hide the "Add as Colleague" link on your My Site deployment in the event that you aren't quite ready to enable that functionality for your users.
- Open your browser and enter http://MySiteWebApp/person.aspx
- Click on Site Actions -> Edit Page
- Locate the Bottom Zone and click Add a Web Part
- Under Categories, select Media and Content
- Under Web Parts, select Content Editor
- Click the Add button
- Locate the newly added web part and click on the dropdown arrow in the upper right hand corner
- Select the Edit Web Part option
- Under Layout, place a check in the Hidden checkbox
- In the Content Editor web part, click on the link that reads Click here to add new content link
- In the Format Text ribbon, click on the HTML button and select Edit HTML Source
- In the HTML Source dialog, enter the following HTML:
<style> .ms-my-addcolleague { DISPLAY: none }</style>
- Click OK
- Click OK
Monday, March 12, 2012
Automatically show "More Information" content on the Person.aspx page of a My Site implementation
By default, the content contained under the "More Information" section of the Person.aspx page (i.e. the information displayed in the ProfileDetailsViewer web part) is hidden and will only display when the user clicks on the More information hyperlink. If you wish to display this content when the user accesses the page, here is one possible option you can use:
- Open your browser and enter http://MySiteWebApp/person.aspx
- Click on Site Actions -> Edit Page
- Locate the Bottom Zone and click Add a Web Part
- Under Categories, select Media and Content
- Under Web Parts, select Content Editor
- Click the Add button
- Locate the newly added web part and click on the dropdown arrow in the upper right hand corner
- Select the Edit Web Part option
- Under Layout, place a check in the Hidden checkbox
- In the Content Editor web part, click on the link that reads Click here to add new content link
- In the Format Text ribbon, click on the HTML button and select Edit HTML Source
- In the HTML Source dialog, enter the following HTML:
- Click OK
- Click OK
<script type="text/javascript"> _spBodyOnLoadFunctionNames.push("ExpandMoreInformationSection"); function ExpandMoreInformationSection() { ShowHideDetails('ProfileViewer_ValueAboutMe', 'ProfileViewer_ProfileDetails', 'ProfileViewer_Ellipsis', 'ctl00_PlaceHolderMain_ctl11', 'More information', 'Hide information');}</script>
Friday, March 9, 2012
Your solution file isn't being displayed in the Visual Studio 2010 Solution Explorer
In it's default state, Visual Studio 2010 isn't configured to display the solution in the Solution Explorer window. If you wish to change the configuration to always display the solution, you can do so via the following steps:
- Open Visual Studio 2010
- Click on Tools -> Options
- Expand the Project and Solutions node
- Click on General
- Place a check in the Always Show Solution checkbox
- Click OK
Subscribe to:
Posts (Atom)