public void Test1()
{
string fileLocation = WebConfigurationManager.AppSettings["FileCreationLoc"].ToString();
string SourceLocation = WebConfigurationManager.AppSettings["FileSource"].ToString();
SourceLocation = SourceLocation + "Upload";
string FileName = string.Empty;
List<string> list = new List<string>();
list.Add("Gksamy");
list.Add("Alex");
list.Add("lenin");
for (int i = 0; i < list.Count; i++)
{
string path = fileLocation + list[i];
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
string[] Source_path = Directory.GetFiles(SourceLocation);
for (int j = 0; j <= Source_path.Length - 1; j++)
{
FileInfo file = new FileInfo(Source_path[j]);
string F_Name = file.Name.ToLower();
if (F_Name.Contains(list[i].ToLower()))
{
FileName = file.Name;
var source = Path.Combine(SourceLocation, FileName);
var destination = Path.Combine(fileLocation + list[i], FileName);
File.Copy(source, destination);
}
}
}
else
{
Directory.CreateDirectory(path);
string[] Source_path = Directory.GetFiles(SourceLocation);
for (int j = 0; j <= Source_path.Length - 1; j++)
{
FileInfo file = new FileInfo(Source_path[j]);
string F_Name = file.Name.ToLower();
if (F_Name.Contains(list[i].ToLower()))
{
FileName = file.Name;
var source = Path.Combine(SourceLocation, FileName);
var destination = Path.Combine(fileLocation + list[i], FileName);
File.Copy(source, destination);
}
}
}
}
}
Web.config
<appSettings>
<add key="FileCreationLoc" value="C:\College\Student\"/>
<add key="FileSource" value="C:\colleges\"/>
</appSettings>
{
string fileLocation = WebConfigurationManager.AppSettings["FileCreationLoc"].ToString();
string SourceLocation = WebConfigurationManager.AppSettings["FileSource"].ToString();
SourceLocation = SourceLocation + "Upload";
string FileName = string.Empty;
List<string> list = new List<string>();
list.Add("Gksamy");
list.Add("Alex");
list.Add("lenin");
for (int i = 0; i < list.Count; i++)
{
string path = fileLocation + list[i];
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
string[] Source_path = Directory.GetFiles(SourceLocation);
for (int j = 0; j <= Source_path.Length - 1; j++)
{
FileInfo file = new FileInfo(Source_path[j]);
string F_Name = file.Name.ToLower();
if (F_Name.Contains(list[i].ToLower()))
{
FileName = file.Name;
var source = Path.Combine(SourceLocation, FileName);
var destination = Path.Combine(fileLocation + list[i], FileName);
File.Copy(source, destination);
}
}
}
else
{
Directory.CreateDirectory(path);
string[] Source_path = Directory.GetFiles(SourceLocation);
for (int j = 0; j <= Source_path.Length - 1; j++)
{
FileInfo file = new FileInfo(Source_path[j]);
string F_Name = file.Name.ToLower();
if (F_Name.Contains(list[i].ToLower()))
{
FileName = file.Name;
var source = Path.Combine(SourceLocation, FileName);
var destination = Path.Combine(fileLocation + list[i], FileName);
File.Copy(source, destination);
}
}
}
}
}
Web.config
<appSettings>
<add key="FileCreationLoc" value="C:\College\Student\"/>
<add key="FileSource" value="C:\colleges\"/>
</appSettings>