Site Storage WebPart
For SharePoint site Administrators it could be important to view the storage of a SiteCollection (and subsites). However, SharePoint sites are often hosted by a external hosting and administrators have no access to the Central Administration. I wrote the following WebPart which summarizes the storage of a SiteCollection and the SubSites of this SiteCollection. Since there's no property for getting the Site Size I make recursively use of the Folder Size of a SPWeb.
public class SiteUsageWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
public SiteUsageWebPart()
{
}
private SPSite siteCollection;
private SPWeb site;
private SPWebCollection sites;
protected override void CreateChildControls()
{
siteCollection = SPContext.Current.Site;
site = SPContext.Current.Web;
sites = siteCollection.RootWeb.Webs;
}
private long GetWebSize(SPWeb web)
{
long total = 0;
foreach (SPFolder folder in web.Folders)
{
total += GetFolderSize(folder);
}
foreach (SPWeb subweb in web.Webs)
{
total += GetWebSize(subweb);
subweb.Dispose();
}
return total;
}
private long GetFolderSize(SPFolder folder)
{
long folderSize = 0;
foreach (SPFile file in folder.Files)
{
folderSize += file.Length;
}
foreach (SPFolder subfolder in folder.SubFolders)
{
folderSize += GetFolderSize(subfolder);
}
return folderSize;
}
private double ConvertBytesToMegabytes(long bytes)
{
return (bytes / 1024f) / 1024f;
}
protected override void Render(HtmlTextWriter writer)
{
writer.WriteLine("<table>");
// Size of the Rootweb
writer.WriteLine("<tr>");
writer.Write("<td><B>" + SPEncode.HtmlEncode(siteCollection.RootWeb.Title) + " (RootWeb)</B></td>");
writer.Write("<td>" + siteCollection.RootWeb.Url + "</td>");
writer.WriteLine("<td>" + SPEncode.HtmlEncode(ConvertBytesToMegabytes(GetWebSize(siteCollection.RootWeb)).ToString("0.00")) + " MB</td>");
writer.WriteLine("</tr>");
foreach (SPWeb subSite in sites)
{
writer.WriteLine("<tr>");
writer.Write("<td><B>" + SPEncode.HtmlEncode(subSite.Title) + "</B></td>");
writer.Write("<td>" + subSite.Url + "</td>");
writer.WriteLine("<td>" + SPEncode.HtmlEncode(ConvertBytesToMegabytes(GetWebSize(subSite)).ToString("0.00")) + " MB</td>");
writer.WriteLine("</tr>");
//SPListCollection lists = subSite.Lists;
//foreach (SPList list in lists)
//{
// writer.Write(SPEncode.HtmlEncode(list.Title)
// e.g. you can also summarize list sizes
//}
}
// Total Size of SiteCollection
writer.WriteLine("<tr><td>-----</td><td>-----</td><td>-----</td></tr>");
writer.WriteLine("<tr>");
writer.Write("<td><B>Total size of sitecollection </B></td>");
writer.Write("<td>" + siteCollection.Url + "</td>");
writer.WriteLine("<td><B>" + SPEncode.HtmlEncode(ConvertBytesToMegabytes(siteCollection.Usage.Storage).ToString("0.00")) + " MB</B></td>");
writer.WriteLine("</tr>");
writer.WriteLine("</table>");
}
}
Adding a product to a catalog using code
You can add a product to a Commerce Server Catalog using the next code. Notice that you have to add a reference to the Microsoft.CommerceServer.Catalog.dll (CommerceSharePointExtensibilityKit) and the Microsoft.CommerceServer.Runtime.dll
BaseCatalog baseCatalog = (BaseCatalog)CommerceContext.Current.CatalogSystem.CatalogContext.GetCatalog("Adventure Works Catalog");
//baseCatalog.CreateProduct(string defintionName, string productId, decimal listPrice, string parentCategoryName);
Product item = baseCatalog.CreateProduct("Tents", "Iglo", 30m, "Tents");
item.DisplayName = "Iglo";
item["Description"] = "Very nice tent";
item.Save();
Commerce Server Inline Product property edition WebPart for SharePoint
One thing where missing using Commerce Services for SharePoint is the ability to administrate products. The following Web Part makes Inline product property edition for commerce server 2009 possible. This silver light control (hosted in ASP.NET web part) helps business people to update product information on their ecommerce websites. http://www.microsoft.com/downloads/details.aspx?FamilyID=fce87672-90cf-4ead-b100-6bbc24d96f66&displaylang=en
To Install:
-
-
Edit the .bat file (by my installation placed at: C:\Program Files (x86)\Microsoft Commerce Server 2007\Microsoft Commerce Server 2009\Site\InstallInlineEditWebPart.cmd)
-
Change the path to the stsadm.exe tool and the url of your site in this .bat file
@ECHO OFF
@SET stsadm="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm.exe" //your stsadm location
@SET url="yourMossUrl"
ECHO **********************************************************************
ECHO Adding WSP
ECHO **********************************************************************
%stsadm% -o addsolution -filename "MicrosoftCommerceInlineEditWebPart.wsp"
%stsadm% -o execadmsvcjobs
ECHO **********************************************************************
ECHO Deploying WSP
ECHO **********************************************************************
%stsadm% -o deploysolution -name "MicrosoftCommerceInlineEditWebPart.wsp" -url %url%
-immediate -allowGacDeployment -allowCasPolicies -force
%stsadm% -o execadmsvcjobs
ECHO **********************************************************************
ECHO Activating Silverlight Feature for editing Commerce Server product properties
ECHO **********************************************************************
%stsadm% -o activatefeature -name "InlineProductEditorWebPart" -url %url% -force
%stsadm% -o execadmsvcjobs
ECHO **********************************************************************
ECHO Activating Silverlight Feature for Inline Product Property Editor resources
ECHO **********************************************************************
%stsadm% -o activatefeature -name "InlineProductEditorResource" -url %url% -force
%stsadm% -o execadmsvcjobs
ECHO **********************************************************************
ECHO Restarting IIS
ECHO **********************************************************************
iisreset
-
Install Silverlight
-
Open your web.config file and add the follow line to the end of the save controls
<SafeControl Assembly="System.Web.Silverlight, Version=2.0.5.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.SilverlightControls"
TypeName="*" Safe="True" />
-
Open the properties window for your IIS server
-
Click the "MIME Types" button. In the new dialog window, choose "Add" to add a new MIME type. The extension is ".XAP", and the MIME type is "application/x-silverlight-app".
SPMessaging V0.2 released
Just released SPMessaging V0.2 on http://www.codeplex.com/SPMessaging. New Features are:
Release is still Beta. I have to add exceptionhandling and delete some "dirty" functions. However if you plan to release something if it's "perfect" it will not be released
so here it is: http://www.codeplex.com/SPMessaging.
WebPart is currently for MOSS Since I load a userprofile for getting the url to the UserPicture from e.g. the mySite. Hope to make it WSS compatible in another release also.
Some nice Regular Expressions used:
// Remove Domain part from username
string userName = Regex.Replace(SPContext.Current.Web.CurrentUser.LoginName.ToString(),
".*\\\\(.*)", "$1",RegexOptions.None);
// Make hyperlink of http:// url
string strContent = txtWhatAreYouDoing.Text;
Regex urlRegex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
strContent = urlRegex.Replace(strContent,"<a href=\"$1\" target=\"_blank\">$1</a>");
// Make hyperlink of emailadres
Regex emailRegex = new Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
strContent = emailRegex.Replace(strContent, "<a href=mailto:$1>$1</a>");
CAML Query comparing current user with a list field
I used the next query to check or the current user (logged in) is the same as the user stored in a specific listfield.
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name=\"Sender\" /><Value Type='User'>" + SPContext.Current.Web.CurrentUser.LoginName.ToString() + "</Value></Eq></Where><OrderBy><FieldRef Ascending='DESC' Name='Created' /></OrderBy>";
SPListItemCollection collListItems = myList.GetItems(query); //myList is a listobject of type SPList
You can get the SPUser object in the following way:
private SPUser GetUserFromList(SPListItem item)
{
string strUserValue = item["Sender"].ToString();
int intIndex = strUserValue.IndexOf(';');
int intID = Int32.Parse(strUserValue.Substring(0, intIndex));
SPUser oUser = this.site.SiteUsers.GetByID(intID);
return oUser;
}
If you like SharePoint and you like Twitter you would like this
A lot of SharePointers (and of course other people) use Twitter. We also have groups on twibes like www.twibes.com/sharepoint and www.twibes.com/sharepointdevelopment. There are also ways to use Twitter in SharePoint. The problem (or opportunity) is the whole world can read your Twitter messages. What do you think about internal Twittering? Sharing short project messages with your project members or collegues?
My first project on CodePlex makes this possible: SPMessaging. It's a WebPart for MOSS2007 using jQuery for sharing short messages in SharePoint. Everybody who has (minimal) read access to your site can read the messages and write messages. If the user has a picture in his or her profile this will automatically loaded. No picture, no problem, a standard image will be shown.
The Messages will be stored in a SharePoint list. This list is automatically created after pushing the "update" button for the first time. You can customize some aspects using the WebPart properties (e.g. max items on a page, max items in a list etc.) If reaching the max items in the list (which you define in de webpart properties), the oldest item will be deleted automatically. E.g. a list does never reach more than 1000 listitems. This feature is to prevent perfomance issues.
It's a proof of concept for me working with jQuery. jQuery prevents for example a postback by browsing the pages of older messages. The current release is a beta. I will work on it (and test) in the next couple of weeks. If you have any comments, ideas, issues or whatever, please contact me.
http://www.codeplex.com/spmessaging If you like to follow me on Twitter: http://www.twitter.com/nickboumans
SharePoint Twitter WebPart
Recently there was a tweet of an old post of
Mike Gannotti about a SharePoint Twitter WebPart. Since a lot of people using Twitter here's the link to the original post:
http://sharepoint.microsoft.com/blogs/mikeg/Lists/Posts/Post.aspx?ID=1202
Commerce Server 2009 - WebPart can not be displayed
After running the SharePoint Commerce Services 2009 Configuration Wizard on my PC I got the following error:
WebPart can not be displayed. The Catalog Name and/or Channel Name have not been cpecified for this site. Please check your Channel Configuration.
Solution:
1) Go to Site Settings
2) View All Site Content
3) Channel Configuration (It's a list)
4) Channel = Default (Note: Case Sensitive)
5) Default catalog = Adventure Works Catalog
Twitter web part for SharePoint
Aidan Garnish has build a twitter webpart for sharepoint. You can find his blog and the webpart @
http://www.aidangarnish.net/blog/post/2009/02/Twitter-SharePoint-web-part.aspx
Create your own WebPart Properties - Editable Properties
You can create custom webpart properties by using editable properties. SharePoint will automatically create a control for your property (e.g. String - TextBox, ENUM - DropDownBox etc.).
using System.ComponentModel;
private string listName = "defaultvalue";
[Personalizable(PersonalizationScope.Shared, false)]
[WebDescription("List Name")]
[WebBrowsable(true)]
[WebDisplayName("Name from the list to Display")]
[Category("Data Settings")]
[DefaultValue("defaultvalue")]
public string ListName
{
get { return listName; }
set { listName = value; }
}