none
Copy Name Field to Title Field in a Document Library

    Question

  • Hi guys

    This might be a silly question however, I'm a bit stuck.

    I need to copy the value of the Name col to the Title col.  I know the code to do this, here is a snippet:

    SPWeb topSite = siteCollection.RootWeb;
    SPDocumentLibrary docLib = (SPDocumentLibrary)topSite.Lists["DocTest"];
    SPListItemCollection items = docLib.Items;

    Then foreach it and add something like item["Title"] = item["Name"]

    As a console application I can run this on my local machine on my test local SP2010 and it does the job.  The problem is though, I don't know how to run this on our live SP2010?  Where do I put the code?  What type of project to I use in VisualStudio?

    VisualStudio is not on our live box so I can't simply run a console app.  I'm new to SP development so don't know where to start really.  I know it's not a webpart so what are my other options.

    Is this crazy???

    Thanks for any help

    David

    Thursday, November 21, 2013 12:29 PM

Answers

  • Hi David,

    If you can log onto the live box, you can run your code. You would just need to grab the .exe for your console application from the folder of your Visual Studio solution (this .exe gets generated whenever you Build your project in Visual Studio).

    That said, you might want to consider using Powershell scripts for this type of processing instead of writing a custom console app; you can access all the same .NET objects in Powershell, though the syntax is different. On a server with SharePoint installed, you can pull up the SharePoint 2010 Management Shell to have a Powershell console session with all the SharePoint snapins pre-loaded.

    If you want the Name to copy to the Title field automatically from now on, you should consider either using a SharePoint Designer workflow or writing an Event Receiver.

    • Marked as answer by DavidgCCC Friday, November 22, 2013 9:48 AM
    Thursday, November 21, 2013 7:28 PM

All replies

  • Hi David,

    If you can log onto the live box, you can run your code. You would just need to grab the .exe for your console application from the folder of your Visual Studio solution (this .exe gets generated whenever you Build your project in Visual Studio).

    That said, you might want to consider using Powershell scripts for this type of processing instead of writing a custom console app; you can access all the same .NET objects in Powershell, though the syntax is different. On a server with SharePoint installed, you can pull up the SharePoint 2010 Management Shell to have a Powershell console session with all the SharePoint snapins pre-loaded.

    If you want the Name to copy to the Title field automatically from now on, you should consider either using a SharePoint Designer workflow or writing an Event Receiver.

    • Marked as answer by DavidgCCC Friday, November 22, 2013 9:48 AM
    Thursday, November 21, 2013 7:28 PM
  • Grab the exe of course.  Can't believe I didn't think of that.

    It worked, thanks.

    Friday, November 22, 2013 9:48 AM