Blog Home  Home Feed your aggregator (RSS 2.0)  
My DasBlog! - C
newtelligence powered
 
Friday, July 01, 2005 12:55:41 PM (GMT Daylight Time, UTC+01:00)  #    Comments [2]   ASP.NET | C#  | 
# Thursday, June 23, 2005
One of my collegea likes to have pop quizes about C# programming snippets. One of the questions he gave us yesterday was the following. If you have two classes class A and class B implementing the same interface and class A is derived from class B and you would cast an instance of class A to the interface which method is called. The one of class A or class B. It is actually very simple...
Thursday, June 23, 2005 8:55:19 AM (GMT Daylight Time, UTC+01:00)  #    Comments [1]   C#  | 
# Wednesday, June 22, 2005

At the blog #region /* mads's thoughts */ an important article is found called "COM objects need tight leash". It gives an example of increasing memory usage when working with the SharePoint object model and th Office interop components.

In that case it seems that the Garbage Collector was cleaning up the managed references which were wrappers around COM objects and these COM objects were not cleaned up.

I have had a similair problem in the past writing wrapper classes in C# around C++ unmanaged code. The unmanaged code was not cleaned up by the garbage collector ofcourse and you had to do that yourself.

http://weblogs.asp.net/mnissen/archive/2005/06/22/414247.aspx
Wednesday, June 22, 2005 10:50:05 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   .NET | C# | SharePoint  | 
# Monday, June 06, 2005
In one of the portals we removed the "Site settings" link from the page to prevent users clicking on it. For some additional users which have administrator rights we created a WebPart containing links to the most needed functionality. This custom WebPart contains a direct link to the settings of the current page, a direct link to the settings of users of the current page and a link to delete the current page and its children.

Monday, June 06, 2005 9:05:29 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C# | SharePoint  | 
# Tuesday, May 24, 2005
For one of our customers we needed a specific overview of their KPI's (Key Perfomance Indicators) per defined SLA (Service Level Agreement). The standard Web Parts deliverd by MOBSA (Microsoft Office Business Scorecard Accelerator) were not providing enough possibilities. We decided to build our own custom Web Part using the MOBSA API. It is a very powerfull API and in this example we use it for showing multiple KPI statuses per defined SLA.

Tuesday, May 24, 2005 1:37:10 PM (GMT Daylight Time, UTC+01:00)  #    Comments [3]   C# | SharePoint  | 
# Monday, May 23, 2005
This weekend i needed a control to show jpeg images based on a folder structure. I decided to create an UserControl and used the Table, TableRow, TableCell, LinkButton and Image classes for generating the view. You could also use a class derived from System.Web.UI.Control and override the Render method for rendering the html.

This control is just an example of how to create your own ImageFolderViewer class. It does not take into account that the images could be portrait or landscape format. So if you need more functionality you have to make the additional changes yourself or wait till i release a better version.

Monday, May 23, 2005 9:36:26 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   ASP.NET | C#  | 
# Wednesday, May 18, 2005

At Rob Howard's blog we can read that CodeSmith 3.0 has been released since Monday May 16th. I agree with him that using code generation tools can save enormous time and prevents common mistakes by writing the same code over and over again.

"Code generation tools represent one of the most interesting areas where a tremendous amount of innovation opportunity still exists for improving the software development process. By automating the process of creating framework, database access, or other common/repeated code patters developers can save time, companies can save money, and users of the end product will get better solutions. Why? Instead of spending hours repeating the same logic flows, data access layers, or implementation frameworks just write it once as a CodeSmith template. That's right -- using .NET code you can write a template for how you want your code to be generated. It's still your code with your formatting your comments and your style -- CodeSmith just helps you write it faster. In fact, you could say it's like hiring your own personal army of developers!"

You can download a free 30 day trial version.

http://weblogs.asp.net/rhoward/archive/2005/05/17/407197.aspx

Wednesday, May 18, 2005 7:40:52 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   .NET | C#  | 
Adam Machanic has posted a month ago an article about SqlDataReader performance tips. One about using an indexer with the ordinal position, a second one about avoiding the Get methods and a third about opening and closing the reader.

Especially the last one is something we all sometimes forget. Thanks to Adam for these tips! :)
Wednesday, May 18, 2005 7:30:09 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C# | Databases  | 
# Tuesday, May 17, 2005

Passing a null value to an int is not possible. The int type is mapped to the System.Int32 structure type and is not capable of storing a null value. Only integer values can be stored in there.

There are two ways which i know of how to solve this problem. The first method is using an object in stead of the int type. For example:

object val = 200;

if (val != null)
{
   return (int)val;
}

In this way you can set the val variable to a null value or an integer value. In case of an integer value you unbox the value to retrieve the integer value.

A second method is using the SqlInt32 type found in namespace System.Data.SqlTypes which is a SQL type. This type supports nullable values. For example:

SqlInt32 val = SqlInt32.Null;

or

SqlInt32 val = 200;

Tuesday, May 17, 2005 10:42:58 AM (GMT Daylight Time, UTC+01:00)  #    Comments [2]   C# | SQL Server  | 
# Thursday, May 12, 2005
This is a very simple example how to transform a Webform.aspx file to a wizard. It contains two buttons and works even when the back and next button of the browser are used...
Thursday, May 12, 2005 12:53:22 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   ASP.NET | C#  | 
# Wednesday, May 11, 2005
If you want to use functionality like SPControl.GetContextWeb(Context).Lists and your trust level is set to WSS_Minimum the code will throw an System.Security.Exception telling you that:

Request for the permission of type Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c failed

This means that the code is partial trusted. Normally if you install your assembly in the GAC it runs with "Full" trust. Microsoft recommends that you install your web part assemblies in the BIN directory for a more secure deployment. Therefor the code becomes partial trusted and some functionality is prohibited by the CAS (Code Access Security) and the trust level set in the web.config...
Wednesday, May 11, 2005 3:14:04 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C# | SharePoint  | 
# Tuesday, May 10, 2005
Todd Bleeker wrote an article in SharePoint Advisor Magazine about "Secure SharePoint Code Using Credential-less impersonation". He Describes a very cool method using the App Pool identity to complete tasks where the authenticated user doesn't have permissions for...
Tuesday, May 10, 2005 3:04:31 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C# | SharePoint  | 
When you use properties you only have a few possibilities. Checkboxes are used for booleans, Text fields are used for doubles, int, strings, etc and a dropdownlist is used for enumerations.

So why not create your own ToolPart with default and/or your own controls? It is even not that difficult. :)

I'm working on a BirthdayWebPart which needs some functionality to select through a dropdown box the contact list. But only enumerations are shown using a dropdown list. So we have to write our own ToolPart...

Tuesday, May 10, 2005 10:49:44 AM (GMT Daylight Time, UTC+01:00)  #    Comments [8]   ASP.NET | C# | SharePoint  | 
# Wednesday, May 04, 2005
I'm always surprised that SharePoint developers do not often use more web part menus instead of adding ToolParts. The user doesn't have to go into edit mode which makes it more user-friendly. This article decribes a method for adding an item to the menu of the web part. The menu of a web part can be found in the upper right corner...
Wednesday, May 04, 2005 9:38:45 AM (GMT Daylight Time, UTC+01:00)  #    Comments [4]   C# | SharePoint  | 
# Thursday, April 28, 2005

I expect that there are a lot of people who already wrote some knowlegde article about this. But it never hurts to explain it again. When you use Response.Transmitfile for transmitting a file to the client it gets the name of the current aspx file.

So how do you set the default name of the file which is downloaded to the client? It is actually very easy. The following code downloads a word file "rapport.doc" to the client:

string pathFileName = @"c:\documents\rapport.doc";
string fileName = System.IO.Path.GetFileName(pathFileName);

Response.ContentType = "application/msword";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.TransmitFile(pathFileName);

Thursday, April 28, 2005 3:41:31 PM (GMT Daylight Time, UTC+01:00)  #    Comments [3]   ASP.NET | C#  | 
# Saturday, April 23, 2005
I like to use singletons in my applications, especially when i don't want to initialise a class all the time when i need it. The idea behind a singleton class is to get an instance by calling a static member method and not be able to instantiate the class yourself. In that way there will only be one instance of the class during the run of the application...
Saturday, April 23, 2005 5:20:55 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   ASP.NET | C#  | 
# Tuesday, April 12, 2005
I got a request from the customer to change the background color of a WSS / Portal page depending on the login rights. This example delivers an example which will do this. But the same example can be used to override any other style defined in SPS.css and OWS.css.
Tuesday, April 12, 2005 1:30:00 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C# | SharePoint  | 
# Tuesday, April 05, 2005

I like to write all my code in C# and therefore i sometimes have to rewrite some examples written in VB.NET. This website is a quick reference guide to highlight some key syntactical differences between VB.NET and C#. Thanks to Tom Shelton, Fergus Cooney and others.

http://www.harding.edu/USER/fmccown/WWW/vbnet_csharp_comparison.html

 

Tuesday, April 05, 2005 8:37:04 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   .NET | C#  | 
# Monday, December 05, 2005

I always forget the exact order in which events fire. So i found the following when i googled and wanna share it with you all :)

Page.Init + Control.Init for every control on the Web Form
The first stage in the page life cycle is initialization. After the page's control tree is populated with all the statically declared controls in the .aspx source the Init event is fired. First, the Init event for the Page object occurs, then Init event occurs for each control on the Page. Viewstate information is not available at this stage.

Page.LoadViewState
After initialization, ASP.NET loads the view state for the page. ViewState contains the state of the controls the last time the page was processed on the server.

Page.ProcessPostData
Post Data gets read from the request and control values are applied to control initalized in stage 1.

Page.Load + Control.Load for each control on the Page
If this is the first time the page is being processed (Page.IsPostback property), initial data binding is performed here.

"Change" events are fired for controls
(TextChanged, SelectedIndexChanged, and similar) The current value (from Post Data) is compared to the original value located in the ViewState. If there is a difference "Changed" events are raised.

Server-side events are fired for any validation controls
Button.Click + Button.Command
The Click and Command events are fired for the button that caused the postback

Page.PreRender + Control.PreRender

Page.SaveViewState
New values for all the controls are saved to the view state for another round-trip to the server.

Page.Render

Monday, December 05, 2005 1:09:45 PM (GMT Standard Time, UTC+00:00)  #    Comments [5]   ASP.NET | C#  | 
# Wednesday, October 26, 2005

Todd wrote a nice article about showing styles when moving your cursor around. A lot of people asked him how to alter elements of WSS WebPart Pages. He gives a good walk-through and some code. Thanks Todd :)

http://mindsharpblogs.com/todd/archive/2005/10/25/798.aspx

Wednesday, October 26, 2005 7:26:50 AM (GMT Daylight Time, UTC+01:00)  #    Comments [1]   C# | SharePoint  | 
# Monday, August 15, 2005
The SPWebCollection returned by the member SPWeb.Webs is a not sorted list of SPWeb objects. So i wrote a class which makes it possible to return a sorted list of SPWeb objects based on the property of a SPWeb. It is basically very simple and uses some standard .NET interfaces for enumerating and comparing.

SPSortedWebCollection col = new SPSortedWebCollection(currentWeb.Webs, "Number");

foreach(SPWeb child in col)
{
...
}
Monday, August 15, 2005 10:05:09 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C# | SharePoint  | 
# Monday, July 25, 2005

Modonovan posted an article which explains how to use the IRuntimeFilter to hide or show WebParts in the Portal. as stated in the article:

"By implementing IRuntimeFilter you are essentially creating a rule or a set of rules that determine if a web part should be displayed or not. For example:

  • SharePoint Portal Server (SPS) uses a IRuntimeFilter for audiences. A user will setup the audiences that are allowed to see a web part (using the advanced section in the web part’s toolpane), then when a user visits the web page the filter runs and determines if the web part should be shown or not. If a virtual server is extended with SPS then the Microsoft.SharePoint.Portal.Audience.AudienceManager filter is installed by default.
  • You could create a custom IRuntimeFilter that determines if a web part should be displayed based on the WSS role the user is a member of. This is what the sample code in this document does
  • You could create a custom IRuntimeFilter that determines if a web part should be displayed based on any arbitrary property or rule(s) that you come up with."

I often use some kind of check in my code behind to find out which roles the current user has and then based on the information i show or hide the WebPart. This solution presented by Modonovan is far better. :) Thanks!!

http://blogs.msdn.com/modonovan/archive/2005/07/07/436394.aspx

Monday, July 25, 2005 2:39:41 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C# | SharePoint  | 
# Thursday, July 21, 2005

Mart Muller did a great post about adding a reply programmatically to a discussion board. Just like my last post about programmatically adding history to an issue in an issue list also this is not described clearly in the documentation of SharePoint. The following code is used:

SPListItem newItem = discussionList.Items.Add();
newItem["Title"] = "Title of item";
newItem["Body"] = "Body Text";
newItem["ThreadID"] = [ThreadID of original thread];
newItem["Ordering"] = [Ordering of original thread] + DateTime.Now.ToString("yyyyMMddhhmmss");
newItem.Update();

Mart's article:

http://blogs.tamtam.nl/mart/SharePointTipAdding
ADiscussionReplyItemInAThreadProgramatically.aspx

Article about adding history to an issue in an issue list:

http://net.bloggix.com/PermaLink,guid,aa4c6b98-2039-432b-af80-b8baf901fdf2.aspx


Thursday, July 21, 2005 12:42:32 PM (GMT Daylight Time, UTC+01:00)  #    Comments [1]   C# | SharePoint  | 

If you create a WebPart containing a multiline TextBox, the TextBox does not size automatically with the width of the WebPart. Requesting the Width of the WebPart is not an option because its not yet in the clients browser. So the following example shows a way of sizing the TextBox to 100% in the WebPart. tbRemark is a TextBox with the TextMode set to TextBoxMode.MultiLine.

protected override void RenderWebPart(HtmlTextWriter output)
{
   output.WriteLine("<style>.StyleRemark { width:100%;height:100; }</style>");

   output.WriteLine("<TABLE id=\"Table1\" cellSpacing=\"1\" cellPadding=\"1\" width=\"100%\" border=\"0\">");
   output.WriteLine("<TR><TD>");

   tbRemark.Text = Remark;
   tbRemark.CssClass = "StyleRemark";
   tbRemark.RenderControl(output);

   output.WriteLine("</TD></TR>");
   output.WriteLine("</TABLE>");
}

Thursday, July 21, 2005 8:51:58 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C# | SharePoint  | 
# Tuesday, July 19, 2005

Paul Brenk has posted some usefull code which shows us how to deserialize a string containing XML to an object using a StringReader and a XmlTextReader object. It also shows us how it handles a XML-array using serialization attributes.

http://blogs.tamtam.nl/paulb/DeserializingAnXmlstringAndXmlArrays.aspx

Tuesday, July 19, 2005 7:25:56 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   C#  | 
# Wednesday, July 13, 2005

Microsoft has a nice collection of controls bundled into a package called "IE Web Controls". Except for the fact that they are fully unsupported some controls are very handy.

I have used the TreeView in a custom WebPart and had some difficulty setting the styles. It seems you have to set the styles DefaultStyle, HoverStyle and SelectedStyle. The DefaultStyle is used when no action takes place, the HoverStyle is set when you hover with your mouse over an item and the SelectedStyle is the style of a selected item. Here are two examples of setting the style in a TreeView.

<mytree:treeview runat="server" 
   
ID="tvwResources" 
   defaultStyle="font-family:Verdana,Arial,Sans-serif;color:#000000;font-size:11px;" 
   hoverStyle="font-family:Verdana,Arial,Sans-serif;color:#000000;font-size:11px;" 
   selectedStyle="font-family:Verdana,Arial,Sans-serif;color:#000000;font-size:11px;>
</mytree:treeview>

Or programmatically

mytree.DefaultStyle["font-family"] = "Verdana,Arial,Sans-serif";
mytree.DefaultStyle["color"] = "#000000";
mytree.DefaultStyle["font-size"] = "11px";

mytree.HoverStyle["font-family"] = "Verdana,Arial,Sans-serif";
mytree.HoverStyle["color"] = "#000000";
mytree.HoverStyle["font-size"] = "11px";

mytree.SelectedStyle["font-family"] = "Verdana,Arial,Sans-serif";
mytree.SelectedStyle["color"] = "#000000";
mytree.SelectedStyle["font-size"] = "11px";

Wednesday, July 13, 2005 7:39:05 AM (GMT Daylight Time, UTC+01:00)  #    Comments [9]   C# | Microsoft  | 
# Friday, July 01, 2005

 If you use for example a Repeater and you do not want to show some field from the DataSource based on a expression, you could use the following solution. This example hides the year when the year in the DataSource is zero.

<asp:Repeater runat="server" id="rptGroup">
   <HeaderTemplate>
      <table>
   </HeaderTemplate>
   <ItemTemplate>
      <tr><td>
         <asp:Label id="lbl" runat="server" 
            Visible='<%#DisplayYear(DataBinder.Eval(Container.DataItem, "year"))%>'>
            <%#DataBinder.Eval(Container.DataItem, "year")%>
         </asp:Label>
      </td></tr>
   </ItemTemplate>
   <FooterTemplate>
      </table>
   </FooterTemplate>
</asp:Repeater>

In the code-behind the following method is added:

public bool DisplayYear(object item)
{
   int year = 0;

   try
   {
      year = Convert.ToInt32(item);
   }
   catch(exception)
   {
   }

   return year != 0;
}

<%#DataBinder.Eval(Container.DataItem, "wi_area")%>
<%#DataBinder.Eval(Container.DataItem, "wi_year")%><%#DataBinder.Eval(Container.DataItem, "co_name")%><%#DataBinder.Eval(Container.DataItem, "wi_amount")%><%#DataBinder.Eval(Container.DataItem, "wi_price", "{0:f}")%>
Copyright © 2010 Alexander Meijers. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: