CodeKeep C# Feed Novembre 13th, 2008
Description: Example of declaring events in C#
Link: http://www.codekeep.net/snippets/87479a23-62b7-4476-bddf-711550f1a61f.aspx
public delegate void StatusUpdateHandler(string Message, int PercentComplete);
public event StatusUpdateHandler StatusUpdate;
public void OnStatusUpdate(string Message, int PercentComplete)
{
if (StatusUpdate != null)
StatusUpdate(Message, PercentComplete);
}

WebReference News Novembre 13th, 2008
->
Copywriting is often a daunting task. It’s not uncommon for a copywriter to spend days or weeks on a project. In this book, you’ll learn how to analyze the copy on an existing site, how to improve the layout of Web sites in relation to SEO, and more. By Lee Underwood. 1110
CodeKeep C# Feed Novembre 13th, 2008
Description: Changing a MOSS Publishing Welcome Page Programatically
Link: http://www.codekeep.net/snippets/798280ad-0f5b-4862-8aa5-6f8b33099b40.aspx
static public void UpdateWelcomePage(SPWeb web, string p)
{
if (PublishingWeb.IsPublishingWeb(web))
{
PublishingWeb pw = PublishingWeb.GetPublishingWeb(web);
PublishingSite site = new PublishingSite(web.Site);
//Set the default page
SPFile welcomefile = web.GetFile(p);
pw.DefaultPage = welcomefile;
pw.Update();
}
}

CodeKeep C# Feed Novembre 13th, 2008
Description: How to create mysite programmatically
Link: http://www.codekeep.net/snippets/0609b2f5-bff3-4b8c-8b1a-02e6a840f680.aspx
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System.Web;
namespace UserProfileCreate
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://servername"))
{
ServerContext context = ServerContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);
string accountName = "domainname\\username";
UserProfile userProfile;
if (profileManager.UserExists(accountName))
{
userProfile = profileManager.GetUserProfile(accountName);
userProfile.CreatePersonalSite();
}
}
}
}
}

CodeKeep C# Feed Novembre 13th, 2008
Description: Change master page programmatically
Link: http://www.codekeep.net/snippets/6ad7047e-c32b-40bc-b6c6-48b154efec73.aspx
var newMaster = properties.Feature.Properties["MasterName"].Value;
if (!string.IsNullOrEmpty(newMaster))
{
using (var curSite = (SPSite)properties.Feature.Parent)
{
using (var curWeb = curSite.OpenWeb(""))
{
//got the current site and root web in site, now set the master Url
//to our master page that should have been uploaded as part
//of our feature
if (curWeb.MasterUrl.Contains("default.master"))
{
curWeb.MasterUrl = curWeb.MasterUrl.Replace("default.master", newMaster);
curWeb.Update();
UpdateLog("MasterUrl property updated for web " + curWeb.Title,
EventLogEntryType.Information);
}
}
}
}

CodeKeep C# Feed Novembre 13th, 2008
Description: cac kieu ma hoa.
Link: http://www.codekeep.net/snippets/69359a27-289a-4443-921f-de6fe6b8075c.aspx
using System;
using System.IO;
using System.Text;
public class CharacterEncodingExample
{
public static void Main()
{
// T?o file gi? các k?t qu?.
using (StreamWriter output = new StreamWriter("output.txt"))
{
// T?o và ghi ra file m?t chu?i ch?a ký hi?u c?a s? PI.
string srcString = "Area = \u03A0r^2";
output.WriteLine("Source Text : " + srcString);
// Ghi các byte du?c mã hóa theo UTF-16
// c?a chu?i ngu?n ra file.
byte[] utf16String = Encoding.Unicode.GetBytes(srcString);
output.WriteLine("UTF-16 Bytes: {0}",
BitConverter.ToString(utf16String));
// Chuy?n chu?i ngu?n du?c mã hóa theo UTF-16
// thành UTF-8 và ASCII
byte[] utf8String = Encoding.UTF8.GetBytes(srcString);
byte[] asciiString = Encoding.ASCII.GetBytes(srcString);
// Ghi m?ng các byte du?c mã hóa theo UTF-8 và ASCII ra file.
output.WriteLine("UTF-8 Bytes: {0}",
BitConverter.ToString(utf8String));
output.WriteLine("ASCII Bytes: {0}",
BitConverter.ToString(asciiString));
// Chuy?n các byte du?c mã hóa theo UTF-8 và ASCII
// thành chu?i du?c mã hóa theo UTF-16 và ghi ra file.
output.WriteLine("UTF-8 Text : {0}",
Encoding.UTF8.GetString(utf8String));
output.WriteLine("ASCII Text : {0}",
Encoding.ASCII.GetString(asciiString));
// Ghi d? li?u xu?ng file và dóng file.
output.Flush();
output.Close();
}
}
}
