Archive for the ‘.NET 2.0’ Category
Posted by CJ on November 3, 2009
When trying to retreive and view data from InfoPath repeating tables using a no code solution you have a couple of options.
1.
When publising your form you can select the column in the repeating table and modify the column function from (first) to (merge). This merges all the repeating values into one column so you can see all the values in your SharePoint View. One problem with this approach
is that the output doesn’t contain a delimiter for each column value so this makes it difficult for reporting
2.
Another option is to add a textbox to the form which will concatinate the values and seperate them via a deliminator (in this case a semi- colon ‘;’).
In the value area of the textbox add the following formula.
xdMath:Eval(xdMath:Eval(/my:travelRequest/my:trips/my:trip, ‘concat(concat(concat(my:Airline_Name, concat(” – “, my:Flight_Identifier)), concat(” – “, my:Destination_EndDate)), “;”)’), “..”)
This outputs “Air France – GL3444 – 2009-11-05;Qantas - DJ3456 – 2009-11-27;”
To display this information in a SharePoint view you need to create a column in the Form Library for example FlightDetails and when you publish the form add a column mapping that maps FlightDetails to your textbox identifier.
Fill out a form and view the Flight information in a SharePoint view concatenated via a semi-colon. Now we have a ‘;’ deliminator we can easily extract/filter data when exported to an excel spreadsheet.
If you want to you can hide the textbox so users don’t see the value when filling out the form.
Posted in .NET 2.0 | Leave a Comment »
Posted by CJ on October 19, 2009
If you implement paging and sorting in a GridView control then you need to maintain column level sorting when you move between pages.
I apoligise for the code formatting but wordpress doesn’t format code blocks very well.
General Methods
//general method to bind grid. Pass in true if this method is called from the page index event
protected void GridBind(bool IsPageIndexEvent)
{
GridRequests.DataSource = SortDataTable(GetRequestsDataTable(LoginCode), IsPageIndexEvent);
GridRequests.DataBind();
}
//get the data from the database and return a DataTable
protected DataTable GetRequestsDataTable(string LoginCode)
{
Requests business = new Requests();
return business.GetUsersRequests(LoginCode).Tables[0];
}
//sort the DataTable and maintain sort direction if called from page index event
protected DataView SortDataTable(DataTable dataTable, bool isPageIndexChanging)
{
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
if (GridViewSortExpression != string.Empty)
{
if (isPageIndexChanging) //pass in true if event fired from pageindex event
dataView.Sort = string.Format(“{0} {1}”, GridViewSortExpression, GridViewSortDirection);
else
dataView.Sort = string.Format(“{0} {1}”, GridViewSortExpression, GetSortDirection());
}
return dataView;
}
else
return new DataView();
}
Sorting
Set the AllowSorting property to ‘true’ for the GridView
Set a couple of properties to maintain sort column and direction across postbacks
private string GridViewSortDirection
{
get { return ViewState["SortDirection"] as string ?? “ASC”; }
set { ViewState["SortDirection"] = value; }
}
private string GridViewSortExpression
{
get { return ViewState["SortExpression"] as string ?? “Request Id”; }
set { ViewState["SortExpression"] = value; }
}
//this method is called to alternate sort direction
private string GetSortDirection()
{
switch (GridViewSortDirection)
{
case “ASC”:
GridViewSortDirection = “DESC”;
break;
case “DESC”:
GridViewSortDirection = “ASC”;
break;
}
return GridViewSortDirection;
}
//alternate sort direction and maintain page index
void GridRequests_Sorting(object sender, GridViewSortEventArgs e)
{
GridViewSortExpression = e.SortExpression;
int pageIndex = GridRequests.PageIndex;
GridBind(false); //pageindex event did not fire binding
GridRequests.PageIndex = pageIndex;
}
Turn paging on in the GridView control and wire up the Grid_PageIndexChanging eventprotectedvoid GridRequests_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridBind(true);//maintain sort direction as we are only navigating between pages
GridRequests.PageIndex = e.NewPageIndex;
GridRequests.DataBind();
}
Posted in .NET 2.0 | 4 Comments »
Posted by CJ on May 29, 2009
This has always been a problem for developers with requirements to support multiple browsers. When writing code various browsers render the exact same peice of code differently. So the development process consists of programming workarounds so they render the same or very similar.
Now we have a free tool that we can use to test multiple browsers easily during our development process.
http://www.xenocode.com/browsers/
Posted in .NET 2.0, .Net 3.0 | Leave a Comment »
Posted by CJ on May 25, 2009
I have been developing inside SharePoint for a while now and while things are getting easier with tools I think this process for developing User Controls inside SharePoint gives me a lot of control.
- I have a Graphical User Interface
- I have a separate project to build and test outside of SharePoint
- I can easily update and view my project html and binary code
Currently this process doesn’t create me any SharePoint Solution files to deploy across environments. I think to achieve this I will need to create a VS 2008 SharePoint Project…but so far these projects seem to add weight and time that I don’t want at the moment…while I am developing.
- Create a VS2008 web project
- In IIS create an IIS Application under your SharePoint web site that has a path to your VS2008 web project created above. This helps for updating content
- In your VS2008 project create some user controls and test that they function
- In VS2008 project properties under the Build Events tab point the Post Build events text box and add a copy statement to copy your .dlls and .pdbs to your SharePoint web sites bin directory. This will deploy a new .dll every time you build your VS2008 project. I had problems when I put the VS2008 project .dll into the GAC…it only worked when I put it into the SharePoint’s web sites bin directory
- Update your master page with CSS references if your VS2008 project contains a style sheet.
- In SPD in your Page Layout add a Register directive to register your user control
“<%@ Register Src=”~/UI/UserControls/JobGoals.ascx” TagPrefix=”uc1″ TagName=”JobGoals” %>”
OR
Update the SharePoint web site web.config file
<pages>
<controls>
<add src=”~/UI/UserControls/MyAttributes.ascx” tagPrefix=”uc1″ tagName=”MyAttributes”/>
<add src=”~/UI/UserControls/JobGoals.ascx” tagPrefix=”uc1″ tagName=”JobGoals” />
</controls>
</pages>
- Add the User Control to the Page Layout
<uc1:JobGoals ID=”JobGoals1″ runat=”server” />
- Update the SharePoinnt web sites web.config file
<SafeControl Src=”~/UI/*” IncludeSubFolders=”True” Safe=”True” AllowRemoteDesigner=”True” />
- Restart IIS, navigate to a page that uses the page layout and you should see your User Control
Because we created a IIS Application under our SharePoint web site and mapped our VS2008 projects .dll output path to our SharePoints web site, updates are extremely simple.
- .ascx changes: modify, save in VS2008 and refresh sharepoint browser
- .ascx.cs changes: modify, save, build in VS2008 and refresh sharepoint browser
Posted in .NET 2.0, .Net 3.0, WSS 3.0 | 2 Comments »
Posted by CJ on May 15, 2009
A list of useful accessibility resources
Microsoft ASP.Net
SharePoint Specific
Tools
Posted in .NET 2.0 | 1 Comment »
Posted by CJ on March 18, 2009
One of the most common programming issues I see when working at clients locations is the way the common .Net DataSet is managed. I see a lot of code written like the first example below which checks if the DataSet table contains any rows. The problem with Example 1 is it expects a couple of things. Firstly that a DataSet (ds) even exists and secondly that it also contains a table. This code will throw an exception if the DataSet is null or no DataSet table exists.
Example 1
//this will throw an exception if ds is null or no table exists
if(ds.Tables[0].Rows.Count > 0)
{
//process data
}
Example 2
So you should write your code checking of empty rows, empty tables and if the DataSet object exists.
if(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
//process data
}
else
{
// it is empty
}
Happy Coding!
Posted in .NET 2.0 | Leave a Comment »
Posted by CJ on March 3, 2009
I created a custom IFrame web part that has a dynamic source property. The client wanted the IFrame to dynamically resize itself to the browsers width and height.
To achieve this we needed to place the web part directly into the page i.e don’t use a webpart zone. A web part zone wraps tables around the IFrame and controls the width and height properties.
I read a few articles about using JQuery….may have to give this a go also.
Posted in .NET 2.0 | Leave a Comment »
Posted by CJ on February 17, 2009
I will be presenting at my local SharePoint user group tomorrow. This will actually be my first SharePoint user group presentation so I am really looking forward to meeting some new people and seeing what is happening in the SharePoint space.
I am talking about the Content Query Web Part and the abstract is below.
Leveraging the Content Query Web Part
Come and learn how to configure one of the most important MOSS web parts in your toolkit. We will walk-through SharePoint’s premier OOTB rollup web part and demonstrate how to display results in 2 or 3 column format and have multiple fields returned in the results. We will also open Visual Studio and demonstrate how to extend its functionality with paging and dynamic filtering.
If you would like to attend then the details are below.

Posted in .NET 2.0 | 1 Comment »
Posted by CJ on January 10, 2009
Posted in .NET 2.0 | Leave a Comment »
Posted by CJ on January 9, 2009
I have just updated my development (Single Server with SQL Server installed) SharePoint machine with the WSS and MOSS December updates. Note there are two updates if you are running MOSS.
To my surprise everything worked a treat.
I only had SP1 installed before I installed the December updates. I didn’t have the Infrastructure update or any other hotfixes installed before applying the updates.
Steps
- I installed the WSS update first.
- I didn’t run SharePoint Configuration wizard
- I installed the MOSS update
- I did run the SharePoint Configuration wizard
The great thing about the December update is that it includes all previous hotfixes from RTM.
Read and download them from here.
http://blogs.msdn.com/sharepoint/archive/2008/12/17/announcing-december-cumulative-update-for-office-sharepoint-server-2007-and-windows-sharepoint-services-3-0.aspx
Posted in .NET 2.0 | Leave a Comment »
Posted by CJ on January 8, 2009
By default, SharePoint web parts are always put into a web part group called “Miscellaneous”.
If you want to automate this process when deploying your web parts as a Feature you can do the following:
In your web parts element manifest file
<ElementManifests>
<ElementManifest Location=”MyWebPart\MyWebPart.xml” /> this is the file you edit
<ElementFile Location=”MyWebPart\MyWebPart.webpart” />
</ElementManifests>
Add the following elements
<Module Name=”WebParts” List=”113″ Url=”_catalogs/wp”>
<File Path=”FlarePoint.MyWebPart.webpart” Url=”FlarePoint.MyWebPart.webpart” Type=”GhostableInLibrary”>
<Property Name=”Group” Value=”FlarePoint Web Parts” />this is what you add for the Group
<Property Name=”Title” Value=”FlarePoint.MyWebPart” />this is what you add for the Title
<Property Name=”WebPartDescription” Value=”FlarePoints MyWebPart description” />this is what you add for the Description
</File>
</Module>
Good post on doing this via the object model
http://blogs.msdn.com/cliffgreen/archive/2008/04/18/adding-web-parts-to-the-web-part-gallery-using-the-sharepoint-object-model.aspx
Posted in .NET 2.0 | 5 Comments »
Posted by CJ on January 6, 2009
I was looking into the differences between the DataViewWebPart and the DataFormWebPart today and I found little information on this topic until I finally came across a SPD blog entry:
http://blogs.msdn.com/sharepointdesigner/archive/2007/04/24/spdatasource-and-rollups-with-the-data-view.aspx
Data View vs. Data Form
Before we go deeper, you may have noticed that many of us use “Data View” and “Data Form” rather interchangeably. In Windows SharePoint Services v2, we shipped a web part called the DataViewWebPart (DVWP). This web part uses XSLT to transform data from Data Retrieval Services to HTML. In Windows SharePoint Services v3, we shipped a web part called the DataFormWebPart (DFWP). The DataFormWebPart still uses XSLT, but now uses ASP.Net 2.0 Data Source Controls for data access. In addition to “view” functionality, the DataFormWebPart also introduced “form” functionality to write back to various data sources. We use Data View generically to refer to the feature set and all of SharePoint Designer’s UI still uses the term Data View.
Posted in .NET 2.0 | Leave a Comment »
Posted by CJ on December 31, 2008
// add Content Editor Web Part
SPFile NewPage = Web.GetFile(NewPageUrl);
SPLimitedWebPartManager mgr;
mgr = NewPage.GetLimitedWebPartManager(PersonalizationScope.Shared);
ContentEditorWebPart wp1 = new ContentEditorWebPart();
wp1.Title = txtPageTitle.Text;
wp1.ChromeType = PartChromeType.TitleOnly;
wp1.AllowClose = false;
XmlDocument doc = new XmlDocument();
string ns1 = “http://schemas.microsoft.com/WebPart/v2/ContentEditor”;
XmlElement elm = doc.CreateElement(“Content”, ns1);
elm.InnerText = txtPageContent.Text;
wp1.Content = elm;
// add Web Part to Left Zone
mgr.AddWebPart(wp1, “Left”, 0);
Posted in .NET 2.0 | 1 Comment »
Posted by CJ on December 16, 2008
Andy is developing a some user controls that allow blend designers to draw objects and translate these into Physics objects.
Check out his cool little demos here.
http://www.andybeaulieu.com/Default.aspx?tabid=67&EntryID=128
I think in 2009 Silverlight will come of age and in 2010 it will burst into mainstream! Just you wait and see
Posted in .NET 2.0 | Leave a Comment »
Posted by CJ on November 27, 2008
Am always looking for this code snippet.
If you try to do this, you will not achieve the desire results:
ddlList1.SelectedItem.Text = dropdownValue;
By doing that, it will overwrite existing items. Not a good idea at all. Try this instead; you can either set FindByText or FindByValue.
ddlList1.SelectedIndex = ddlList1.Items.IndexOf(ddlList1.Items.FindByText(dropdownText));
Or
ddlList1.SelectedIndex = ddlList1.Items.IndexOf(ddlList1.Items.FindByValue(dropdownValue));
Posted in .NET 2.0 | 1 Comment »
Posted by CJ on November 27, 2008
A post that I know I will need again.
string
strServer = \\\\printservername;
//if the computer is local machine, use the “.” instead
ConnectionOptions options = new ConnectionOptions();
options.Username = “username”;
options.Password = “pswd”;
options.Authority = “NTLMDOMAIN:domain”;
ManagementScope myScope = new ManagementScope(strServer + \\root\\cimv2, options);
SelectQuery oQuery = new SelectQuery(“SELECT * FROM WIN32_Printer”);
ManagementObjectSearcher oResults = new ManagementObjectSearcher(myScope, oQuery);
//Iterate through printers…
foreach (ManagementObject oItem in oResults.Get())
{
string strPrinterName = oItem.Properties["DeviceID"].Value.ToString();
|
Posted in .NET 2.0 | Leave a Comment »
Posted by CJ on November 27, 2008
I regulary run Post Build events in Visual Studio on my development machines to install assemblies into the GAC immediatley after a successful build. This save me a lot of time.
However, have been working with Windows Server 2008 and Visual Studio 2008 and couldn’t find the GacUtil.exe in the usual spots on the file system … e.g C:\Program Files\Microsoft Visual Studio 9.0\SDK.
I finally found the location and it has been moved to C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin
So I can know put in my Post Build events like this:
“C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil.exe” -u “$(TargetName)”
“C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil.exe” -i “$(TargetPath)”
Posted in .NET 2.0 | Leave a Comment »
Posted by CJ on November 18, 2008
Stopping and Starting the wss search service seems to create some problems.
If you stop the service and then try to start it again I received a common error
“Databases must be empty before they can be used. Delete all of the tables, stored procedures and other objects or use a different database.”
So I entered a different database name and then received a error “File Not Found”. I initially thought that this error was referring to the database and that the database wasn’t being thus displaying this error. However I did find out that the new search database was in fact being created so the error must be referring to something else.
The event logs had a warning and two errors referring to registry issues.
Warning – Event ID 10035 – Windows SharePoint Services 3 Search
Could not import the registry hive into the registry because it does not exist in the configuration database.
Context: Application ‘bf3cdd2c-561d-4cd4-aba0-37ddf776115b’
Error – Event ID 10029 – Windows SharePoint Services 3 Search
Error backing up registry hive to the configuration database.
Context: Application ‘Search index file on the search server’
Details: Access is denied. (0×80070005)
Error – Event ID 2426 – Windows SharePoint Services 3 Search
Advise Status Change failed. The system is probably low on resources. Free up resources and restart the service.
Context: Application ‘Search’, Catalog ‘index file on the search server Search’
Details:(0×80041812)
Hmmm…..I finally came across this article http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Microsoft_IIS/Q_22875574.html which discuses changing the Search Service account and Content account to use an administrator. Once I did this all was good and the service started.
I then completed a couple of stsadm commands and everything was working fine.
stsadm –o spsearch –action fullcrawlstop
stsadm –o spsearch –action fullcrawlstart
The Search Service account and the Content account mustn’t have had enough permissions to modify the registry which I wouldn’t have thought was needed. The article also mentiones that they worked with Microsoft on this issue and they recomended using one single service account for single server installations. This is the first time I have heard this.
Normal practice is not to use an administrator account to crawl content as you should use the principle of least privileges.
Anyway, hopefully this will help a few people out.
Posted in .NET 2.0 | 4 Comments »
Posted by CJ on November 5, 2008
Breeze and DDLS are teaming up again to deliver two advanced SharePoint courses.
Breeze and DDLS offer a wide range of SharePoint courses nationally and overseas and I have been lucky enough to be part of the team delivering great course material on a product I am passionate about.
Register and view the course outline below:
Both courses are targeted to SharePoint professionals wanting to learn best practices in architecting and administering SharePoint solutions.
Posted in .NET 2.0 | Leave a Comment »
Posted by CJ on November 4, 2008
I have come across a few deployment issues using VSeWSS. These issues can be time consuming so I am going to start posting Errors and Solutions.
Note: There obviously may be more than one solution to an error so don’t take this as Gospel.
- Error
- Feature ‘75a0fea7-c54f-46b9-86b1-2e103a8fedba’ is not installed in this farm, and can not be added to this scope
- Solution
- I had an error in my web.config file. As soon as I fixed this I redeployed from VSeWSS
- Error
- This solution contains two assemblies with the same name, or the SharePoint server already has an assembly with the specified name
- Solution
- Uninstall the assembly from bin or GAC and then redeploy from VSeWSS
- Error
- The Feature name …. already exists in SharePoint. You need to rename the Feature before solution deployment can succeed
- Solution
Deactivate the feature (if it is activated)
Delete the Feature …. from the 12/Template/Feature directory and redeploy from VSeWSS
- Error
- Cannot find this file specified in the manifest file: FileName …
- Solution
- Open the Manifest file (Use WSP View) and remove the offending line and redeploy from VSeWSS
- Error
- Feature …. is already activated at scope [url]
- Solution
- Deactivate feature through UI or stsadm if hidden
Posted in .NET 2.0 | 3 Comments »