List<string> SOIDs;
List<string> filesInDatabase = GetDatabaseFileName(out SOIDs);
List<string> filesOnServer = GetServerFileNames();
foreach ( string fileName in filesOnServer )
{
string fileOnly = Path.GetFileNameWithoutExtension(fileName).ToString();
if ( filesInDatabase.Contains(fileOnly) )
{
int index = filesInDatabase.IndexOf(fileOnly);
if (index >= 0)
{
if ( !File.Exists(SOIDs[index]) )
{
txtFiles.AppendText(fileOnly + " " + SOIDs[index] + "\r\n");
}
}
}
}
}
protected static List<string> GetDatabaseFileName( out List<string> SOID)
{
List<string> returnValue = new List<string>();
SOID = new List<string>();
using ( SqlConnection connection = new SqlConnection(@"Server=TSQLTVS;UID=*****;PWD=**********;Database=Flowtiva"))
{
connection.Open();
using ( SqlCommand command = connection.CreateCommand() )
{
command.CommandType = CommandType.Text;
command.CommandText = @"SQL query here";
using ( SqlDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection) )
{
while ( dataReader.Read() )
{
returnValue.Add(dataReader.GetString(0));
SOID.Add(dataReader.GetString(1));
}
}
}
}
return returnValue;
}
protected static List<string> GetServerFileNames()
{
List<string> returnValue = new List<string>();
if (Directory.Exists("\\\\disk2\\images\\Missing Images"))
{
string[] files = Directory.GetFiles("\\\\disk2\\images\\Missing Images");
returnValue.AddRange(files);
}
return returnValue;
}
}