Skip to main content

Posts

Showing posts from 2007

XmlTextWriter, encoding and stream

When using XmlTextWriter to write XML to a memory stream, you can specify the encoding type when create the XmlTextWriter instance. Dim oStream As IO.MemoryStream = New IO.MemoryStream() Dim oXmlWriter As New Xml.XmlTextWriter(oStream, System.Text.Encoding.ASCII) oXmlWriter.WriteStartDocument() 'Top level (Parent element) oXmlWriter.WriteStartElement("Invoice") 'Child elements, Invoice Message oXmlWriter.WriteStartElement("InvoiceMessage") oXmlWriter.WriteString("This is a test.") oXmlWriter.WriteEndElement() oXmlWriter.WriteEndElement() 'End top level element oXmlWriter.WriteEndDocument() 'End Document oXmlWriter.Flush() 'Write to stream If you want to read the content from the underlining memory stream, you might be using following code: oStream.Position = 0 Dim oContent(oStream.Length) As Byte oStream.Read(oContent, 0, oStream.Len

SharePoint Audience

Import classes and methods in Microsoft.Office.Server.Audience name space: 1. The AudienceManager class is the entry point for the audience feature in Microsoft Office SharePoint Server 2007. Audiences: This property return all the audiences as AudienceCollection GetUserAudienceIDs: Get all the audience IDs to which the specified user (or current user) belongs to. 2. Audience class: Audiences are groups of users determined by their memberships in Microsoft Exchange distribution lists (DL) or SharePoint groups, or by rules configured by a portal administrator. Audiences allow organizations to target content to users based on their job or task, as defined by their membership in a SharePoint group or distribution list, by the organizational reporting structure, or by the public properties in their user profiles. GetMembership: Gets an ArrayList of UserInfo objects that contains membership information for this audience. IsMember: Determines wheth

ASP.NET Inline Code Syntax Reference

Rendering Code Syntax: <% %> and <%= %> Code enclosed by <% ... %> is just executed, while expressions that include an equal sign, <%= ... %>, are evaluated and the result is emitted as content. Data Binding Syntax: <%# %> Code located within a <%# %> code block is only executed when the DataBind method of its parent control container is invoked. Expression Syntax: <%$ ... %> ASP.NET 2.0 adds a new declarative expression syntax for substituting values into a page before the page is parsed. This is useful for substituting connection string values or application settings defined in a Web.config file for server control property values. It can also be used to substitute values from a resource file for localization.

Using resource file in VSTO 2005 project

VSTO 2005 have default resource file in MyProject folder. If you right click the project in VSTO 2005 and choose properties, you will see project properties window. In the properties window, there is a tab called Resources. You can add default resources, such as images, strings and icons. For the string of different culture, you have to add new resource file into the project. The resource file name follows the format of Resources. language-culture .resx. For example, the resource file for Canadian French is Resources.fr-CA.resx. You add the new resource file by right click the project and choose Add -> New Item.... In the Add New Item dialog, choose Resources File. In the file name box, enter the proper file name as described above, then click OK. You can then add culture specific resources into the newly created resource file.

.NET Generic Constraints Syntax

Generic supports four types of constraints: Interface: Allow only types that implement specific interfaces to use your generic Base class: Allow only types that is or inherited form specific base class to use your generic Constructor: Allow only types that implement specific constructors to use your generic Reference or value type: Limit the types to use your generic either reference type or value type Examples for these constraints: Interface: T must implement IComparable interface public class MyGenericClass where T: IComparable Base class: T must be or inherited from MyBaseClass public class MyGenericClass where T: MyBaseClass Constructor: T must have at least the default constructor available public class MyGenericClass where T: new () Reference or value type: T must be a reference type public class MyGenericClass where T: class Reference or value type: T must be a value type public class MyGenericClass where T: struct

Location, Location, Location

In WSS 3.0 Site definition, we have a manifest.xml file to describe the content in solution file and how to deploy the content. In the XML element of manifest.xml file, there are many location attributes to use. It is confusing where these locations reference. Here are some clues: 1. SiteDefinitionManifest node: The location of this node reference to SiteTemplates folder under TEMPLATE directory. For example: <SiteDefinitionManifest Location="MyCustomSite" /> will create a subdirectory called MyCustomSite under …12\TEMPLATE\SiteTemplates and copy all the contents under MyCustomSite directory in solution file into …12\TEMPLATE\SiteTemplates\MyCustomSite. In your solution file, you need to have a directory called MyCustomSite and put all your customized site pages in it. Inside this directory, you need to create a directory called XML and put onet.xml inside it. 2. FeatureManifest node: The location of this node references to FEATURES folder under …12\TEMPLATE. For exampl

Element.xml explained

Some xml elements in Element.xml file in WSS 3.0: 1. Root element: Elements. It contains a Id attribute, which is a guid to uniquely identify this element. 2. Receivers element: This element is inside Elements. It contains ListTemplateId attribute which specifies what type of list will be attached to list item event handler. For example, a value of 101 means that the event handler will be attached to all document libraries. 3. Receiver element: This element is inside Receivers element. It contains several sub elements in it to define the class to receive list item event. A sample configure is like this: <receiver> <name>DigiDoc signature check event <type>ItemUpdated <sequencenumber>5000 <assembly>wssDigiDoc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=44b3223b8da05605 <class>wssDigiDoc.ddocEventHandler </> Name: A descriptive name Type: The event type that this receiver class will handle. The possible values are: ItemAdd, ItemUpdate, It

Features.xml explained

Some xml elements in Features.xml file in WSS 3.0: 1. Root element: Feature. It contains following attributes: Id: The guid to uniquely identify this feature. Title: The title of the feature appears in feature list Description: The descriptive text appears in feature list Version: Feature version number Scope: The scope this feature applies to. The possible values are: Web, Site, WebApplication and Farm Hidden: A boolean value to indicate if to show this feature in feature list xmlns: Xml namespace, always "http://schemas.microsoft.com/sharepoint/" ImageUrl: The image icon that appears at the left of the feature in feature list. The image should be in \IMAGES if no path is given. ReceiverAssembly: This is the full qualified assembly name that contains the event handler of feature installation/uninstallation, activation/deactivation. ReceiverClass: This is the class name in ReceiverAssembly that actually handles feature related events. This class must inherit SPFeatureReceiv

Users, AllUsers and SiteUsers

SPWeb object has three properties related to user collection: Users: The individual user added into site. This use does not belong to any site group. AllUsers: All the users in site group of this site, including both the individual users and the users in site groups. SiteUsers: All the available users in the site collection, including some hidden users added by WSS.

Change the field display color based on its value

This is tested on WSS 3.0. I have a custom list definition. There is a field called "Status" in this list definition. I want to change the display color of this field based on its value. Here is the steps: In the schema.xml file of this list, find the "Status" field definition. It should be inside /List/MetaData/Fields. Based on this field, create another Computed type field. Here is the code snippet: <Field Type="Text" DisplayName="Status" ReadOnly="TRUE" Required="TRUE" MaxLength="255" ID="{d9daabac-0014-4c1e-8c06-093ff0c7ecfc}" SourceID="{142fdfdd-7e46-4ca3-b9d3-56ae0ead646e}" StaticName="Status" Name="Status" ColName="nvarchar3" RowOrdinal="0" /> <Field ID="{0864C5F6-688C-4ee5-A4FE-3FB17CD5EE1E}" ReadOnly="TRUE" Type="Computed" Name="ColorStatus" DisplayName="Status" Dir="" DisplayNameS

Request URL

Example: http://localhost:8080/webapp/webform1.aspx?cmd=edit&UserName=John%20Smith Request.RawUrl: /webapp/webform1.aspx?cmd=edit&UserName=John%20Smith Request.Path: /webapp/webform1.aspx Request.PhysicalPath: D:\Web Dev\WebApp\WebForm1.aspx Request.BaseDir: /WebApp Request.Url.Host: localhost Request.Url.Port: 8080 Request.Url.Scheme: http Request.Url.CurrentDocument: WebForm1.aspx Request.Url.Query: ?cmd=edit&UserName=John%20Smith Request.Url.DisplayQuery: ?cmd=edit&UserName=John Smith Request.Url.AbsoluteUri: http://localhost:8080/webapp/webform1.aspx?cmd=edit&UserId=123 Request.Url.Authority: localhost:8080

Load .csv file into dataset

Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim file As String = "Test2.txt" Dim path As String = "C:\" Dim ds As New DataSet Try Dim f As System.IO.File If f.Exists(path & file) Then Dim ConStr As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _ path & ";Extended Properties=""Text;HDR=No;FMT=Delimited\""" Dim conn As New OleDb.OleDbConnection(ConStr) Dim da As New OleDb.OleDbDataAdapter("Select * from " & _ file, conn) da.Fill(ds, "TextFile") End If Catch ex As Exception MessageBox.Show(ex.ToString) End Try DataGrid1.DataSource = ds.Tables(0) End Sub

Customize Trace in ASP.NET 2.0

By default, ASP.NET 2.o provides 3 trace listeners: DefaultTraceListener: Used in Visual Studio Environment TextWriterTraceListener: redirect tracing output to an instance of the TextWriter class or to any object that is a Stream class, such as a log file, network stream, or console EventLogTraceListener: redirect tracing messages to Windows event log You can derive your customized listener from these listeners or from the abstract base class TraceListener. There are several methods you can override, but the most important ones are Write and WriteLine. Trace configuration: Trace can be controlled using the configuration file. The following configuration has configured an event log trace listener. All the trace information will be routed to event log named EventLogName . <configuration> <system.diagnostics> <trace autoflush="true" indentsize="2"> <listeners> <remove name="Default"/> <add name="EventLogListener" typ
Use SharePoint Context Menu in Pure Web Application Include required styles and JavaScript files <script src="http://catorontdv71/_layouts/1033/owsbrows.js"></script> <script src="http://catorontdv71/_layouts/1033/ows.js"></script> <script language='javascript' src='http://catorontdv71/_layouts/1033/ie55up.js'></script> <script src="http://catorontdv71/_layouts/1033/Menu.js" type="text/JavaScript" language="JavaScript"></script> <script type="text/JavaScript" language="JavaScript"> <!-- var L_Menu_BaseUrl="http://catorontdv71"; var L_Menu_LCID="1033"; var L_Menu_SiteTheme=""; //--> </script> <script> if (browseris.mac && !browseris.ie5up) { var ms_maccssfpfixup = "http://catorontdv

Site Group .vs. Cross Site Group

Site group and cross site group are a great way to manage SharePoint site permission. Cross site group, compared to site group or Active Directory group, has more benefits. Cross site group is created in site collection level. Its working scope is the site collection, that is top level site and all its sub sites. While site group is only working in one individual site. Cross site group name can be the same in different site groups, but contains totally different users. While using Active Directory group, the group name must be unique across all site collections. Cross site group is much easier to manage. It does not need the IT department to create every single group you need in Active Directory for your SharePoint sites. When your SharePoint sites grow more and more, these Active Directory groups management will be a big issue.

SharePoint Web Part Cache .vs. ASP.NET cache

One major difference between web part cache and ASP.NET cache is web part cache can be stored per user or per web part, while the ASP.NET cache is global in one web application. Using web part cache, it is impossible to share cache between different web part instances (Same type web parts). C# protected void PartCacheWrite ( Storage storage, string key, Object value, TimeSpan timeout ) In the web part cache write method, the first parameter storage is an enumerate value, it can be Personal or Shared. When it is set to Personal, the cache is per user basis; when it is set to Shared, the cache is per web part basis. Also we can notice that there is no dependency capability in web part cache.

Develop Asynchronous Web Parts

By default, custom web part uses synchronous mechanism. If in a web part page, there are many web parts, each web part takes some time to retrieve data from either web service or back end database. The overall performance of the web part page will likely be bad. All the web parts rendered in sequence. Second web part must wait until first web part finishes its rendering, third web part must wait until second web part finished its work. The solution is to use asynchronous mechanism. Asynchronous support is built into the SharePoint web part framework and is very easy to use. You need to follow these steps to use asynchronous call. Derive a custom Web Part class from base WebPart class in Microsoft.SharePoint.dll assembly. Override method named GetRequiresData . Override method named GetData In GetRequiresData method return a value of true. It tells the Web Part framework to call your overridden version of GetData method. In GetData method, register a custom callback method by calling

SharePoint 2003 Single SignOn

There is a very good article in Microsoft TechNet talking about Microsoft Single SignOn service. It discusses Single SignOn architecture, configuring and managing Single SignOn and how to use Single SignOn in web parts. Single Sign-On in SharePoint Portal Server 2003 There is another good posting in MSDN blogs providing a good example about how to use Microsoft Single SignOn service. It also contains sample code to download: Impersonation, Single Sign-on, and SPS If you want to integrate 3rd party Single SignOn service into SharePoint 2003, read this article. It gives an example of how to use SiteMinder Single SignOn service for SharePoint 2003 server. Integrating 3rd Party Single Sign On in Sharepoint Portal Server

MOSS 2007 Shared Service Provider (SSP)

Shared Service Provider. This is a collection of application servers that provide shared services out to any portals or sites that need them. These services include: Search Index Audience compilation User profiles database My Sites Business Data Catalogue Excel Services Any of the above services can exist on any number of servers on SSP except Index service, which can only have one per SSP. SSP has no affiliation to portal. In MOSS 2007, portal (web application) is just a site collection with no application services inside. All the application services will be provided by SSP. It's possible to create two different SSPs within the same server farm, each with its own configuration. Within a MOSS 2007 farm, each Web application is associated with exactly one SSP. Reference: MOSS Architecture and Shared Services

SharePoint 2003 and Exchange 2003 Integration

There are 3 possible ways to integrate SharePoint 2003 and Exchange Server 2003: Using the Exchange Web Parts Displaying Exchange Data in a Page Viewer Web Part Creating an E-Mail-Enabled Document Library Using the Exchange Web Parts: SharePoint 2003 provides 4 web parts that can display Exchange mailbox data. These web parts are: My Calendar My Inbox My Mail Folder My Tasks Display Exchange Data in a Page Viewer Web Part: You can use Page Viewer web part to display content in Exchange Server 2003 public folder. Configure the URL in page viewer web part to point to: http:// exchangeservername /public/company%20meetings/?cmd=contents&view=monthly Possible view parameter can be daily, weekly and monthly. It is case sensitive. Creating an E-Mail-Enabled Document Library SharePoint 2003 document library can be linked to Exchange public folder, so any files attached to the message sent to public folder will be copied to linked document library. Exchange will also populat

Javascript null and undefined

In javascript language, null is a special object. When you declare a variable and do not assign any value to it, the following evaluation will return true: var a; if(a == null) alert("a is null"); if(!a) alert("!a is true"); You will see both alert boxes. However, if there is no variable a defined in your javascript function, the evaluations above will cause a javascript error. To avoid the javascript error, you should use the following statement to check if the variable is defined or not: // a is not defined anywhere in your javascript // if(!a) will throw an exception // if(a == null) will also throw an exception // following statement will show the alert box if(typeof(a) == 'undefined') alert("variable a is not defined yet");