R
Reason101
Guest
Hi, I am using below c# code which is working fine. But I will be receiving 5-10MB files which using this process have to load in memory and I think its a bit risky and throttling issue may arise. Can any of you experts please advise is below code is good approach ?
2. Also, I am doing a File.copy.
But if File Exist in the folder, I need to overwrite it. How to do this ?
3. After loading in the memory, I need to delete the file one after another from Source folder. Where should I do this ?
public void LoadFiles ()
{
byte[] input = null;
var files = Directory.EnumerateFiles(SourcePath, "*.pdf")
.OrderBy(f => f)
.Take(NumberOfFiles);
string[] abc = files.ToArray();
for (int i = 0; i < files.Count(); i++)
{
if (File.Exists(abc))
{
//Archieving the files
// File.Copy(abc, String.Concat(ArchievePath, Path.GetFileName(abc)));
File.WriteAllText(abc, String.Concat(ArchievePath, Path.GetFileName(abc)));
Stream fs = File.OpenRead(abc);
using (MemoryStream memoryStream = new MemoryStream())
{
fs.CopyTo(memoryStream);
input = memoryStream.ToArray();
}
CreateOutgoingMessage(pContext, input, pInMsg, Path.GetFileName(abc));
fs.Close();
// File.Delete(abc);
}
}
Reason101
Continue reading...
2. Also, I am doing a File.copy.
But if File Exist in the folder, I need to overwrite it. How to do this ?
3. After loading in the memory, I need to delete the file one after another from Source folder. Where should I do this ?
public void LoadFiles ()
{
byte[] input = null;
var files = Directory.EnumerateFiles(SourcePath, "*.pdf")
.OrderBy(f => f)
.Take(NumberOfFiles);
string[] abc = files.ToArray();
for (int i = 0; i < files.Count(); i++)
{
if (File.Exists(abc))
{
//Archieving the files
// File.Copy(abc, String.Concat(ArchievePath, Path.GetFileName(abc)));
File.WriteAllText(abc, String.Concat(ArchievePath, Path.GetFileName(abc)));
Stream fs = File.OpenRead(abc);
using (MemoryStream memoryStream = new MemoryStream())
{
fs.CopyTo(memoryStream);
input = memoryStream.ToArray();
}
CreateOutgoingMessage(pContext, input, pInMsg, Path.GetFileName(abc));
fs.Close();
// File.Delete(abc);
}
}
Reason101
Continue reading...