R
rta_vix
Guest
Friends, I'm having trouble solving my problem to move the file. After some changes to my code, I'm getting a different error. Follow all my code for better understanding.
StackTrace:
in System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks (String fullPath)
in System.Security.Permissions.FileIOPermission.QuickDemand (FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
in System.IO.File.InternalMove (String sourceFileName, String destFileName, Boolean checkHost)
in System.IO.File.Move (String sourceFileName, String destFileName)
in ImportValue.ReadText.MoveFile (String FileName) in C: \ Users \ rtaVix\ Desktop \ ImportComportant \ ImportedError \ ImportedError \ ReadingTxt.cs: line 233
in ImportCurrent.ReadText.TranslateFilter (String FullPathFile) in C: \ Users \ rtaVix \ Desktop \ ImportComportant \ ImportedError \ ImportedError \ ReadingTxt.cs: line 216
() at C: \ Users \ rtaVix \ Desktop \ ImportCurrent \ ImportCurrent \ ImportCurrent \ ReadText.cs: line 60
in System.Threading.ThreadHelper.ThreadStart_Context (Object state)
in System.Threading.ExecutionContext.RunInternal (ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
in System.Threading.ExecutionContext.Run (ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
in System.Threading.ExecutionContext.Run (ExecutionContext executionContext, ContextCallback callback, Object state)
in System.Threading.ThreadHelper.ThreadStart ()
My codes and line error:
private static void ProcessFile (string FullPathFile)
{
try
{
bool Move = true;
string [] StringLine = System.IO.File.ReadAllLines (FullPathFile);
string CodBarra = "";
for (int line = 0; line <StringLine.Length; line ++)
{
string DateScheduling = "";
string DocumentValue = "";
string Protocol = "";
string Record = "";
string Emission = "";
#region Retrieve the Barcode
if (String [line] .Contains ("Bar Cod:"))
{
CodBar + = String [line] .Replace ("Cod. Bars:", "");
line + = 2;
}
if (CodeBar! = "")
{
CodBar + = String [line];
CodBar = CodBar.Replace ("", "");
}
#endregion
if (CodeBar == "")
continues;
line + = 6;
#region Scheduling Date
if (String [line] .Contains ("Delay:"))
{
DateScheduling + = String [line] .Replace ("DateScheduling :", "") .Replace ("", "");
}
#endregion
line + = 2;
#region Document Value
if (String [line] .Contains ("Vlr.Documento:"))
{
DocumentValue + = String [line] .Replace ("Document.Value :", "") .Replace ("", "");
}
#endregion
line + = 2;
#region Protocol
if (String [line] .Contains ("Protocol:"))
{
Protocol + = String [line] .Replace ("Protocol:", "") .Replace ("", "");
}
#endregion
line + = 12;
#region Registration
if (String [line] .Contains ("Record:"))
{
Record + = String [line] .Replace ("Record:", "");
}
#endregion
line + = 2;
#region Issue
if (String [line] .Contains ("Emission:"))
{
Emission + = String [line] .Replace ("Emission:", "");
}
#endregion
// Search Bar Code
string CodProcInter = GetCodProcInter (CodBar);
// string name_interested = Getname_interested (CodeBar);
if (! string.IsNullOrEmpty (CodProcInter))
{
if (! CodeBarInserted (CodeBar))
{
// Insert Bar Code
bool inserted = BankInfo (CodProcInter, CodeBar, DateScheduling , DocumentValue, Protocol, Register, Emission);
}
else
{
// Bar Code Already Inserted
InsertLog ("\ n Already Exists ->" + CodeBar);
}
}
else
{
// Barcode not available in table -> sdpj_proc_inter
Move = false;
InsertLog ("\ n The file was not imported because the Bar Code ->" + CodeBarra + "is not available in the interested process table");
}
// Clear Variables
CodBarra = "";
}
if
{
MoveFile (FullPathFile);
}
}
catch (Exception) // line 216
{
throw;
}
}
private static void CheckTime ()
{
while (true)
{
if (DateTime.Now.Hour == 16) // If it is 07:00 AM in the morning
{
try
{
DirectoryInfo dirPending = new DirectoryInfo (PendingPlacesFolder);
// list files in the current directory
foreach (FileInfo file in dirPending.GetFiles ())
{
if (file.Extension == ".cpv")
{
InsertLog ("");
// nsertLog ("\ n HOME ::" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());
InsertLog ("\ n START:" + file.FullName + "" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());
Process File (file.FullName);
}
}
}
catch (Exception)
{
throw; // line 60
}
finally
{
InsertLog ("\ n FIM ::" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());
}
}
Thread.Sleep (3600000); // 3,600,000 milliseconds equals 1 hour (Standby)
}
}
Modified move code:
private static void MoveFile (string FileName)
{
string rootFolderPath = "D:\\Pendrive\\PENDING\\";
string destinationPath = "D:\\Pendrive\\IMPORTED\\";
string [] fileList = System.IO.Directory.GetFiles (rootFolderPath);
foreach (string file in fileList)
{
string fileToMove = rootFolderPath + file;
string moveTo = destinationPath + file;
// moving file
File.Move (fileToMove, moveTo); // line 233
}
}
Continue reading...
StackTrace:
in System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks (String fullPath)
in System.Security.Permissions.FileIOPermission.QuickDemand (FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
in System.IO.File.InternalMove (String sourceFileName, String destFileName, Boolean checkHost)
in System.IO.File.Move (String sourceFileName, String destFileName)
in ImportValue.ReadText.MoveFile (String FileName) in C: \ Users \ rtaVix\ Desktop \ ImportComportant \ ImportedError \ ImportedError \ ReadingTxt.cs: line 233
in ImportCurrent.ReadText.TranslateFilter (String FullPathFile) in C: \ Users \ rtaVix \ Desktop \ ImportComportant \ ImportedError \ ImportedError \ ReadingTxt.cs: line 216
() at C: \ Users \ rtaVix \ Desktop \ ImportCurrent \ ImportCurrent \ ImportCurrent \ ReadText.cs: line 60
in System.Threading.ThreadHelper.ThreadStart_Context (Object state)
in System.Threading.ExecutionContext.RunInternal (ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
in System.Threading.ExecutionContext.Run (ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
in System.Threading.ExecutionContext.Run (ExecutionContext executionContext, ContextCallback callback, Object state)
in System.Threading.ThreadHelper.ThreadStart ()
My codes and line error:
private static void ProcessFile (string FullPathFile)
{
try
{
bool Move = true;
string [] StringLine = System.IO.File.ReadAllLines (FullPathFile);
string CodBarra = "";
for (int line = 0; line <StringLine.Length; line ++)
{
string DateScheduling = "";
string DocumentValue = "";
string Protocol = "";
string Record = "";
string Emission = "";
#region Retrieve the Barcode
if (String [line] .Contains ("Bar Cod:"))
{
CodBar + = String [line] .Replace ("Cod. Bars:", "");
line + = 2;
}
if (CodeBar! = "")
{
CodBar + = String [line];
CodBar = CodBar.Replace ("", "");
}
#endregion
if (CodeBar == "")
continues;
line + = 6;
#region Scheduling Date
if (String [line] .Contains ("Delay:"))
{
DateScheduling + = String [line] .Replace ("DateScheduling :", "") .Replace ("", "");
}
#endregion
line + = 2;
#region Document Value
if (String [line] .Contains ("Vlr.Documento:"))
{
DocumentValue + = String [line] .Replace ("Document.Value :", "") .Replace ("", "");
}
#endregion
line + = 2;
#region Protocol
if (String [line] .Contains ("Protocol:"))
{
Protocol + = String [line] .Replace ("Protocol:", "") .Replace ("", "");
}
#endregion
line + = 12;
#region Registration
if (String [line] .Contains ("Record:"))
{
Record + = String [line] .Replace ("Record:", "");
}
#endregion
line + = 2;
#region Issue
if (String [line] .Contains ("Emission:"))
{
Emission + = String [line] .Replace ("Emission:", "");
}
#endregion
// Search Bar Code
string CodProcInter = GetCodProcInter (CodBar);
// string name_interested = Getname_interested (CodeBar);
if (! string.IsNullOrEmpty (CodProcInter))
{
if (! CodeBarInserted (CodeBar))
{
// Insert Bar Code
bool inserted = BankInfo (CodProcInter, CodeBar, DateScheduling , DocumentValue, Protocol, Register, Emission);
}
else
{
// Bar Code Already Inserted
InsertLog ("\ n Already Exists ->" + CodeBar);
}
}
else
{
// Barcode not available in table -> sdpj_proc_inter
Move = false;
InsertLog ("\ n The file was not imported because the Bar Code ->" + CodeBarra + "is not available in the interested process table");
}
// Clear Variables
CodBarra = "";
}
if
{
MoveFile (FullPathFile);
}
}
catch (Exception) // line 216
{
throw;
}
}
private static void CheckTime ()
{
while (true)
{
if (DateTime.Now.Hour == 16) // If it is 07:00 AM in the morning
{
try
{
DirectoryInfo dirPending = new DirectoryInfo (PendingPlacesFolder);
// list files in the current directory
foreach (FileInfo file in dirPending.GetFiles ())
{
if (file.Extension == ".cpv")
{
InsertLog ("");
// nsertLog ("\ n HOME ::" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());
InsertLog ("\ n START:" + file.FullName + "" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());
Process File (file.FullName);
}
}
}
catch (Exception)
{
throw; // line 60
}
finally
{
InsertLog ("\ n FIM ::" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());
}
}
Thread.Sleep (3600000); // 3,600,000 milliseconds equals 1 hour (Standby)
}
}
Modified move code:
private static void MoveFile (string FileName)
{
string rootFolderPath = "D:\\Pendrive\\PENDING\\";
string destinationPath = "D:\\Pendrive\\IMPORTED\\";
string [] fileList = System.IO.Directory.GetFiles (rootFolderPath);
foreach (string file in fileList)
{
string fileToMove = rootFolderPath + file;
string moveTo = destinationPath + file;
// moving file
File.Move (fileToMove, moveTo); // line 233
}
}
Continue reading...