Friday, August 7, 2009

Office Space: Events in SharePoint 2007

Office Space: Events in SharePoint 2007: "Events in SharePoint 2007"

Exporting Visual Studio Solutions with SolutionFactory : b#

Exporting Visual Studio Solutions with SolutionFactory : b#: "Exporting Visual Studio Solutions with SolutionFactory"

SPFeatureCollection Class (Microsoft.SharePoint)

SPFeatureCollection Class (Microsoft.SharePoint): "SPFeatureCollection Class (Microsoft.SharePoint)"

The following code example activates a Web site-scoped Feature with the specified title in all the subsites of a specific site collection.
This example requires using directives (Imports in Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.
C#

Copy Code

System.Globalization.CultureInfo oCultureInfo = new
System.Globalization.CultureInfo(1033);
SPFeatureDefinitionCollection collFeatureDefinitions =
SPFarm.Local.FeatureDefinitions;
foreach (SPFeatureDefinition oFeatureDefinition in
collFeatureDefinitions)
{
if (oFeatureDefinition.GetTitle(oCultureInfo) == "Feature_Title")
{
Guid guidFeatureDefinitionID = oFeatureDefinition.Id;
SPWebCollection collWebsites =
SPContext.Current.Site.AllWebs["Site"].Webs;
foreach (SPWeb oWebsite in collWebsites)
{
if (oFeatureDefinition.Scope == SPFeatureScope.Web)
{
SPFeatureCollection collFeatureCollection =
oWebsite.Features;
SPFeature oFeature =
collFeatureCollection.Add(guidFeatureDefinitionID);
Response.Write(SPEncode.HtmlEncode(oFeature.Definition.GetTitle(oCultureInfo)) + " feature added on " + oWebsite.Title + "
");
}
oWebsite.Dispose();
}
}
}

Using PowerShell to activate a feature across all Sharepoint 2007/WSS 3.0 sites and subsites | David's technobabble

Using PowerShell to activate a feature across all Sharepoint 2007/WSS 3.0 sites and subsites David's technobabble: "Using PowerShell to activate a feature across all Sharepoint 2007/WSS 3.0 sites and subsites"

Thursday, August 6, 2009

WSPBuilder - Walkthrough of the Visual Studio Add-in - Tobias Zimmergren's thoughts on development

WSPBuilder - Walkthrough of the Visual Studio Add-in - Tobias Zimmergren's thoughts on development: "WSPBuilder Installation
Just download the latest release of the 'WSPBuilder Extensions - Visual Studio Addin' and let the installation guide take you through the most simple process ever - clickety click.
Creating a WSPBuilder project
When you have installed the add-in to Visual Studio, you should now be able to create a new project based on the 'WSPBuilder' template.
To kick this off, let's create our WSPBuilder project:"

** WSPBuilder - Walkthrough of the Visual Studio Add-in - Tobias Zimmergren's thoughts on development

WSPBuilder - Walkthrough of the Visual Studio Add-in - Tobias Zimmergren's thoughts on development: "WSPBuilder - Walkthrough of the Visual Studio Add-in"

** Favorite CodePlex SharePoint Projects - Fear and Loathing

Favorite CodePlex SharePoint Projects - Fear and Loathing: "Favorite CodePlex SharePoint Projects"

*** HOWTO: Create an Event Handler for SharePoint(MOSS 2007) « Koen’s Weblog

HOWTO: Create an Event Handler for SharePoint(MOSS 2007) « Koen’s Weblog: "HOWTO: Create an Event Handler for SharePoint(MOSS 2007)"

Wednesday, August 5, 2009

Recycling IIS app pools

Recycling IIS app pools: "Recycling IIS app pools"

Attach to Process with one shortcut

Attach to Process with one shortcut: "Attach to Process with one shortcut"

SharePoint: How to debug event handlers - didierdanse.net - Development News

SharePoint: How to debug event handlers - didierdanse.net - Development News: "SharePoint: How to debug event handlers"

SharePoint: How to debug event handlers - didierdanse.net - Development News

SharePoint: How to debug event handlers - didierdanse.net - Development News: "If you are using Microsoft Office SharePoint Server 2007, you can directly write information in these logs. You have to add a reference to Microsoft.Office.Server.dll DLL located in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI\ folder. Then, in your code, add the following instruction: Microsoft.Office.Server.Diagnostics.PortalLog.LogString(“your text”);"

Attach to Process with one shortcut

Attach to Process with one shortcut: "Attach to Process with one shortcut"

Monday, August 3, 2009

Is it a good idea to use lambda expressions for querying SharePoint data? - Waldek Mastykarz

Is it a good idea to use lambda expressions for querying SharePoint data? - Waldek Mastykarz: "Is it a good idea to use lambda expressions for querying SharePoint data?"

Move or Copy SharePoint Document Library Files Programmatically

In this post I published some code that took a look at using FrontPage Server Extentions to upload a file to a document library where the requirement was to be able to save metadata along with the document and not use the API. Here are a few more static methods that can be inserted into that code to provide simple file moving or copying functionality from a remote client. Documentation about the move RPC method can be found here. To copy rather than move the file, change the doCopy flag to true. An alternative method for remotely moving a file from one document library to another location is to use the copy web service which is documented on MSDN here. For local SharePoint calls, the appropriate API method is SPListItem.CopyTo or SPFile.MoveTo.

Update: You can download a comprehensive c# class library to automate RPC calls - including moving files (even between web sites or servers). See this blog post for more information.

 public static bool Move(string oldUrl, string newUrl)
        {
            string result = "";
            string webUrl = GetWebURL(oldUrl);
            oldUrl = oldUrl.Substring(webUrl.Length + 1);
            newUrl = newUrl.Substring(webUrl.Length + 1);
            return Move(webUrl, oldUrl, newUrl, out result);
        }
 
        public static bool Move(string webUrl, string oldUrl, string newUrl, out string result)
        {
            EnsureFolders(webUrl, newUrl);
            string renameOption = "findbacklinks";
            string putOption = "overwrite,createdir,migrationsemantics";
            bool doCopy = false;
            string method = "method=move+document%3a12.0.4518.1016&service_name=%2f&oldUrl={0}&newUrl={1}&url_list=[]&rename_option={2}&put_option={3}&docopy={4}";
            method = String.Format(method, oldUrl, newUrl, renameOption, putOption, doCopy.ToString().ToLower());
            try
            {
                using (WebClient webClient = new WebClient())
                {
                    webClient.Credentials = CredentialCache.DefaultCredentials;
                    webClient.Headers.Add("Content-Type", "application/x-vermeer-urlencoded");
                    webClient.Headers.Add("X-Vermeer-Content-Type", "application/x-vermeer-urlencoded");
                    result = Encoding.UTF8.GetString(webClient.UploadData(webUrl + "/_vti_bin/_vti_aut/author.dll", "POST", Encoding.UTF8.GetBytes(method)));
                    if (result.IndexOf("\n

message=successfully"

) <>
                        throw new Exception(result);
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
                return false;
            }
            return true;
        }
 
        public static void EnsureFolders(string rootUrl, string folderUrl)
        {
            StringBuilder sb = new StringBuilder(rootUrl.TrimEnd('/'));
            string[] segments = folderUrl.Split('/');
            for (int i = 0; i <>
            {
                sb.Append("/");
                sb.Append(segments[i]);
                CreateFolder(sb.ToString());
            }
        }
 
        public static bool CreateFolder(string folderURL)
        {
            try
            {
                WebRequest request = WebRequest.Create(folderURL);
                request.Credentials = CredentialCache.DefaultCredentials;
                request.Method = "MKCOL";
                WebResponse response = request.GetResponse();
                response.Close();
                return true;
            }
            catch (WebException)
            {
                return false;
            }
        }

Moving Documents from One Document Library to Another

Moving Documents from One Document Library to Another:

As you all know I write a lot of maintenance console applications to perform upgrades on huge subsets of sites. This week I was asked to create a console application that will cut down six documents libraries into three document libraries. I wanted to use the CopyTo() Function, but there is a bug. I did find a nice MoveTo() Function in SPFile. I ended up using that code instead here is a little sample:

//copy documents and deletes libraries
SPList ProposalsWord = Web.Lists["Proposal Template (Word)"];
foreach (SPListItem Item in ProposalsWord.Items)
{
SPFile File = Web.GetFile(Item.Url);
try
{
File.MoveTo(Web.Url + "/Sample%20Proposals%20PDF/" + Item["Name"].ToString());
}
catch (Exception)
{
}
}
ProposalsWord.Delete();

This piece of code loops through the items on one document library and moves them to another document library. It is fairly simple and straight forward. If you have any comments or questions please let me know.