in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Team Eli's blog

October 2008 - Posts

  • Record Center / Information Management Policy Jobs Not Running

    Interesting enough, we noticed after installing “something” (it could have been Project Server, Service Pack 1 or even the Infrastructure Update) that none of the time jobs managed by the PolicyConfig service were running.   If fact, they were all list as have never run, which I knew is a lie since they used to work at some point in time.  These jobs include:

    Expiration Policy
    Hold Processing and Reporting
    Information Management Policy
    Records Center Processing

    In trying to troubleshoot this issue, I was messing around with one of the stsadm commands that can be used to set the when these four polices run.  However, when I tried to run the following command:

    Stsadm –o setpolicyschedule –schedule “daily at 23:50:00”

     I would get an error saying “The Information Management Policy feature is not active.”  After a little bit more research, I found out that the “feature” that it is complaining about is the RecordsManagment feature.  Granted, this feature is scope at the Farm level and thereby is automatically activate, I took the liberty and ran

     stsadm –o activatefeature –name RecordsManagement –force. 

    After running the re-activate command, I was then able to run the setpolicyschedule command (which I didn’t need to do to resolve the issue) and volia my Information Management Policy’s timer jobs are running again!

     

  • Use Powershell to get a new GUID

    In SharePoint development, you are always in need of generating a unique id (aka GUID) for your features and solutions.  While most developers have a GUID generator setup in Visual Studio, here is a quick alternative if you don't want to open Visual Studio but have Powershell open.

    [System.Guid]::NewGuid().ToString()

     And volia...you have a new GUID that you can use in your application.

    Eli

     

  • TeamEli's first CodePlex Project -- GUI to Add Solutions to SharePoint Solution Store

    Well, I finally took the time to sit down and put together a CodePlex project for some of the application pages (ok...only one so far...) that I am building for SharePoint admins.  So far, I have an application page that allows SharePoint admins to upload SharePoint solutions into the solution store.  This gets rid of the need to have to log into the server to run that one pesty stsadm command (addsolution).  I am not sure if anybody will find this useful but I figured it would be a nice start for my presence on CodePlex.

    TeamEli SharePoint (2007) Tools

     As far as the application goes, it's fairly straight forward.  A custom application page that resides in the ADMIN folder with a custom action on the operations page right underneath the Solutions Management link.  Turns out it is pretty easy to add new solution files to the store.  First, I have to save a copy of the file locally so that the API can access the file then I check to see if the solution already exists.  If it does, it upgrades the solution.  Otherwise, it just adds the solution to the store.

    // Saves file to local system so that sharepoint can upload it
    string path = "C:\\Packages\\" + upload_Solution.FileName;
    upload_Solution.SaveAs(path);

    // Gets current solution (if present)
    SPSolution solution = SPFarm.Local.Solutions[upload_Solution.FileName];

    if (solution == null)
    {
         
    // Adds new solution to farm
         
    solution = SPFarm.Local.Solutions.Add(path);
    }
    else
    {
        
    if (solution.Deployed)
         {
              
    // Upgrades the solution now.
              
    solution.Upgrade(path, DateTime.Now);
         }
        
    else
        
    {
             
    // Removes solution and re-adds it
             
    solution.Delete();
              solution =
    SPFarm.Local.Solutions.Add(path);
         }
    }

    Please feel free to give it awhirl and let me know what your thoughts are and if you have any problems.

    Eli

  • Use SharePoint API to Create Wiki Page

    I had the task of auto generating hundreds of Wiki pages (basically a wiki of commonly used terms for my client's line of business).  The data was read from a Tab delimited file and in order to create Wiki pages, we have to do a few things differently.  Below is the .NET / SharePoint code that can be used to create a new Wiki page.

    string
    fileName = "TestWiki";
    string body = "This is the body of the Wiki. Can contain <b>HTML</b>";

    SPSite site = new SPSite("http://localhost");
    SPWeb web = site.OpenWeb();
    SPList list = web.Lists["Wiki"];

    string serverRelativeUrl = web.ServerRelativeUrl + list.Title + "/" +fileName+ ".aspx";

    SPListItem item = list.RootFolder.Files.Add(serverRelativeUrl, SPTemplateFileType.WikiPage).Item;
    item[
    "WikiField"] = body;
    item.UpdateOverwriteVersion();

    web.Dispose();
    site.Dispose();

    Hope this helps to save somebody some time.

    Eli

  • Powershell Script -- Start Custom Timer Job Out of Schedule

    I find it sometimes that I need to start one of my custom timer jobs ahead of schedule (normally for testing purpose) so I decided to put together a Powershell that calls the execute method of the SPJobDefintion.

    OneTimeJob.ps1 

    param
    (
     [string] $jobName
    )

    [void][reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint")

    $service = [Microsoft.SharePoint.Administration.SPWebService]::AdministrationService
    $webApps = $service.WebApplications

    foreach ($webApp in $service.WebApplications)
    {
         $job = $webApp.JobDefinitions | where { $_.Name -eq $jobName } 

         if ($job -ne $NULL)
         {
               $job.Execute([system.guid]::Empty)
               Write "Job Executed"
         }
         else
         {
               Write "Job Not Found"
         }
    }

    # END SCRIPT

    To run, pass in the name of the time job class.

     \OneTimeJob.ps1 "TeamEli.SharePoint.OneTimer"

     Hope this saves somebody some time.

    Eli


Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts