Shortlink

Copy Files Between Web Applications and Keep Metadata

What if you need to move all the files in one document library to a library in a different web app. Along with this, you also need to maintain your metadata. This includes the content types, file created by, created on, modified, and modified by metadata.

In my Dev environment, I created a simple Windows Form app.
Add a reference to the SharePoint Dll.
I named my app MoveDataSP.

In the scenario below, the code will copy the contents of folder1 from the sourceSPsite to the destinationSPsite. Both sites have libaries named the same (libraryName).

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;

namespace MoveDataSP
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public static void CopyFolderToAnotherSiteCollection(string sourceUrl, string destinationUrl,
          string listName, string folderUrl, string folderName)
        {
            string listRelatvieFolderUrl = folderUrl.Substring(folderUrl.IndexOf("/") + 1);
            using (SPSite sourceSite = new SPSite(sourceUrl))
            {
                using (SPWeb sourceWeb = sourceSite.OpenWeb())
                {
                    SPFolder sourceFolder = sourceWeb.GetFolder(folderUrl);
                    using (SPSite destSite = new SPSite(destinationUrl))
                    {
                        using (SPWeb destWeb = destSite.OpenWeb())
                        {
                            if (!destWeb.GetFolder(folderUrl).Exists)
                            {
                                SPListItem destItem = destWeb.Lists[listName].Items.Add(string.Empty, SPFileSystemObjectType.Folder, listRelatvieFolderUrl);

                                destItem.Update();
                            }

                            SPFolder destFolder = destWeb.GetFolder(folderUrl);

                            foreach (SPFile file in sourceFolder.Files)
                            {   
                                SPUser sCreatedby = destWeb.AllUsers[file.Author.ToString()];
                                SPUser sModifiedBy = destWeb.AllUsers[file.ModifiedBy.ToString()];
                                DateTime dCreated = file.TimeCreated;
                                DateTime dModified = file.TimeLastModified;

                                SPFile sFile = destFolder.Files.Add(file.Url, file.OpenBinary(), file.Properties, sCreatedby, sModifiedBy, dCreated, dModified, true);

                                SPListItem item = sFile.Item;

                                item["Created By"] = sCreatedby;
                                item["Modified By"] = sModifiedBy;
                                item["Created"] = dCreated;
                                item["Modified"] = dModified;

                                sFile.Item.SystemUpdate();

                            }

                            foreach (SPFolder folder in sourceFolder.SubFolders)
                            {
                                CopyFolderToAnotherSiteCollection(sourceUrl, destinationUrl, listName, folder.Url, folder.Name);
                            }
                        }
                    }
                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            CopyFolderToAnotherSiteCollection("http://sourceSPsite/", "http://destinationSPsite", "libraryName", "libraryName/folder1", "folder1");
        }

    }
}

Most of the code above was borrowed from this post:
http://sharepointfieldnotes.blogspot.com/2009/11/how-to-copy-files-across-site.html

Shortlink

Set Title Field to Hidden in a Content Type

                        using (SPWeb newWeb = web.Site.OpenWeb(web.ID))
                        {
                            cT = newWeb.ContentTypes[cT.Id];
                            SPField myField = cT.Fields[field.Title];
                            cT.FieldLinks[myField.Id].Hidden = true;
                            cT.Update(true);
                            newWeb.Update();
                        }
Shortlink

tiiniywalleet spyware removal

I was struck by this mess of a spyware virus and it took good amount of time to remove.

You will see stuff all over the web on how to remove TinyWallet, but this was different. tiiniywalleet wouldn’t react to any of the popular tools.

In the long run, I ended up uninstalling Chrome, then ran Cclearner.

Uninstall Chrome
Follow these steps:
http://malwaretips.com/blogs/remove-tinywallet-virus/
Then run CCleaner