We are trying to move files to SharePoint but need to rename them first since many have invalid characters. A previous developer started the script below. Any suggestions on how to adept it to check for valid file names and then rename the invalid files?
Thanks for any assistance,
Cali
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.SharePoint;
using System.Data.SqlClient;
using System.Threading;
namespace SPMoveFiles
{ class Program
{
private static string site, web, list, problem;
private static SPSite mySite;
private static SPWeb myWeb;
static void Main(string[] args)
{
Console.WriteLine("Enter the directory of the files you would like to migrate.");
string filePath = Console.ReadLine();
RenameFiles(filePath);
}
//This method needs to be changed.
private static void RenameFiles(string filePath){
string[] files = Directory.GetFiles(filePath);
foreach (string fileName in files)
{
//Concatenate the file to 20 characters.
//Replace invalid characters with an underscore.
}
string[] dirs = Directory.GetDirectories(filePath);
foreach (string dirName in dirs)
{
//Here, if the directory is greater than 20 characters, we must concatenate it to 20 characters.
}
}
return result;}
}
}
Cali
Comment