C
C#

help

Hei all, I am new to this Server and I realy need help on specific Problem [Answered]

MMeistro10/10/2022
I am trying to move a .csv File from a Folder to another and it is actualy working but when I open the transfered File and compare it with the original one, the new File seem to be completly different. It is broken. There are new Characters in the new file which are not existing in the Origin one. Thanks in advance
Eero10/10/2022
pelase share your code with us
MMeistro10/10/2022
else //Move file from a folder to another
{
sr.Close();

{ //Move File to destination
string moveFrom = fileToMove; //source path
string moveTo = destinationPath_Failed + Filename; //destination

// Ensure that the target does not exist.
if (File.Exists(moveTo))
File.Delete(moveTo);

//moving file
File.Move(moveFrom, moveTo); //something went wrong here. I dont know why. The programm is not copying the file originaly
}
else //Move file from a folder to another
{
sr.Close();

{ //Move File to destination
string moveFrom = fileToMove; //source path
string moveTo = destinationPath_Failed + Filename; //destination

// Ensure that the target does not exist.
if (File.Exists(moveTo))
File.Delete(moveTo);

//moving file
File.Move(moveFrom, moveTo); //something went wrong here. I dont know why. The programm is not copying the file originaly
}
Eero10/10/2022
looks fine
MMeistro10/10/2022
the csv looks like this: "some text one the first line" after tranfer it looks like this: "some text one the first line ; ; ; ; ;; ; ; ;; ; " and it is writing a number in this length: 23452356345634563 to nomething like this: 23452E+16
Eero10/10/2022
hm, that doesn't seem right moving a file just copies the raw bytes i'm pretty sure
MMeistro10/10/2022
hmm I am realy comfusing and I realy need to finish this but dont know how to solve it :/ sorry for disturbing you
Eero10/10/2022
i don't think the issue is with moving the file
MMeistro10/10/2022
do you think its the File ? but it should still copy it correctly and originaly but it doesnt
Eero10/10/2022
i'm not really sure, you'll have to show us more code
MMeistro10/10/2022
MMeistro10/10/2022
string strResult = sr.ReadToEnd(); //save file innerbody to a string
string[] result = strResult.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); //split String in lines und save every Line in an Array

int i = 0;
List<string> converted = new(result);
if (!converted[0].Contains("H;")) //remove all blanks a initial H
{
for (int j = 0; j < result.Length; j++)
{
if (result[j].Contains("H;"))
{
while (!converted[i].Contains("H;"))
{
converted.RemoveAt(i);
}
break;
}
}

result = converted.ToArray();
}

i = result.Length - 1;
if (!result[i].Contains("T;")) //remove all blanks at initial T
{
for (int j = 0; j < result.Length; j++)
{
if (result[j].Contains("T;"))
{
while (!result[i].Contains("T;"))
{
result = result.SkipLast(1).ToArray();
i = result.Length - 1;
}
break;
}
}
}

int data = Get_datensaetze_anzahl(result); //count Datas... all line that have the inital D

string strResult = sr.ReadToEnd(); //save file innerbody to a string
string[] result = strResult.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); //split String in lines und save every Line in an Array

int i = 0;
List<string> converted = new(result);
if (!converted[0].Contains("H;")) //remove all blanks a initial H
{
for (int j = 0; j < result.Length; j++)
{
if (result[j].Contains("H;"))
{
while (!converted[i].Contains("H;"))
{
converted.RemoveAt(i);
}
break;
}
}

result = converted.ToArray();
}

i = result.Length - 1;
if (!result[i].Contains("T;")) //remove all blanks at initial T
{
for (int j = 0; j < result.Length; j++)
{
if (result[j].Contains("T;"))
{
while (!result[i].Contains("T;"))
{
result = result.SkipLast(1).ToArray();
i = result.Length - 1;
}
break;
}
}
}

int data = Get_datensaetze_anzahl(result); //count Datas... all line that have the inital D

this part is actualy only to count Datas in the csv but I dont change the CSV
KKouhai /人◕ ‿‿ ◕人\10/10/2022
Comment out all the code, and just do the move operation File.Move shouldn't corrupt the data
Eero10/10/2022
and especially not turn a number from its full representation to the exponent one
KKouhai /人◕ ‿‿ ◕人\10/10/2022
Oh, I didn't notice they said that 😅 Yeah, it's 100% not File.Move
MMeistro10/10/2022
ok ok I will comment those other things out and try the move acion only thank you so much for your time guys ! I´ll give a feedback in a moment Hei Hei, me again. I´ve found something weird. I comented out this line
var files = from file in Directory.EnumerateFiles(rootFolderPath, "*.csv") select file;
var files = from file in Directory.EnumerateFiles(rootFolderPath, "*.csv") select file;
and replaced it with this one
string[] files = System.IO.Directory.GetFiles(rootFolderPath, "*.csv");
string[] files = System.IO.Directory.GetFiles(rootFolderPath, "*.csv");
and for some reason the files arent brocken. might it be the problem ?
KKouhai /人◕ ‿‿ ◕人\10/10/2022
Directory.EnumerateFiles can't change your files content
Eero10/10/2022
Also just a completely pointless linq query
MMeistro10/10/2022
ok ok .... still dont get the File distroyer 😄 ok thank you anyways. Could you not close this Help section ? I would liek to give you a Feedback as soon as I found something. I have tested something else. When I open the original file and Copy everything to my clipboard and paste it in a text file. It produces the same broken file as my Code but I dont know where in the code it does such problem
AAccord10/10/2022
Ask the thread owner or member with permission to close this!
Eero10/10/2022
that sounds weird, don't know about that
MMeistro10/10/2022
its a .csv file btw .csv have many custom settings and grids in it ... ok anyways. Thank you guys have a nice day 🙂
KKouhai /人◕ ‿‿ ◕人\10/10/2022
How are you viewing your CSV content? In a text editor or as a table?
MMeistro10/10/2022
after the File.move I opend it with both. Text editor(notepad++) and table(excel)
KKouhai /人◕ ‿‿ ◕人\10/10/2022
And how are you copying the original file's data to your clipboard? From excel or notepad++
MMeistro10/10/2022
this is the corrupted file content example: H;1;270345392022;4632;;;;;;;;;;;;;;;;;;;;;;; and this is the original H;1;70345392022;4632 from notepad and put it in csv
KKouhai /人◕ ‿‿ ◕人\10/10/2022
That same corrupted data happen when copy to the clipboard?
MMeistro10/10/2022
yes.... but its just a test... I wanted to reproduce the move by hand but I dont know if its the right ways
KKouhai /人◕ ‿‿ ◕人\10/10/2022
That's very weird, would you be able to share the original csv?
MMeistro10/10/2022
emmm oh sorry ... I cant 😦 becauz its an intern data I could make an example for you
Eero10/10/2022
i can only imagine this happening if you copy data from like one OS to another like between the OS and a VM
KKouhai /人◕ ‿‿ ◕人\10/10/2022
Hmmm, if you can make a reproducible example that might help 😅 But anyhow, I would honestly open the original file in a hex editor and examine the contents
MMeistro10/10/2022
hex editor ? sorry for late response I tryed to reproduce a file with no errors but seems that as soon as I edtited the file it also corrupted it sooo weird haha
MMeistro10/10/2022
here is an example When I open thi sin excel it shows everything normal but when I edit it it give those weird semicolon and same when I run the File.move in code I will respond you in 1 Hour... I have to travel with train now 😄 no Internet on my way
KKouhai /人◕ ‿‿ ◕人\10/10/2022
Your best bet is to open the original file in a hex editor and examine it
MMeistro10/11/2022
ok thank you I will try it. Sorry I was busy when I came home. Back to office. i will try it out now I tryed the Hex thing but cant figure it out how it is possible that it adds more characters than it has after moving the file
KKouhai /人◕ ‿‿ ◕人\10/11/2022
How many bytes does the file have before and after moving?
MMeistro10/12/2022
oh thats a good question but good hint ! I will check out ass soon as I have the posibility ... I have found out a reproduce way. open this in excel, then save it and close it. next open it with notepad and you will see that there are semicolons on top line and last line
KKouhai /人◕ ‿‿ ◕人\10/12/2022
First off, these commas are added to pad header Second H;1;2, why are commas and semicolons both used to separate cells? Third, saving in excel is different from copying the file.
CCisien10/12/2022
moving a file just updates the filesystem metadata, it doesn't copy bytes. that's why moves can be significantly faster than copies
Eero10/12/2022
it's a floating point number? 2,70346E+14
KKouhai /人◕ ‿‿ ◕人\10/12/2022
You're probably right, but that won't work well with CSV
MMeistro10/17/2022
how do I even make Copys in C# ?
Mmtreit10/17/2022
What do you mean? This is true if the move is to a location on the same drive 😉
MMeistro10/17/2022
Here Moving only updates… but how do i perform a copy
Mmtreit10/17/2022
Of a file?
MMeistro10/17/2022
Yes ^^
Mmtreit10/17/2022
File.Copy
MMeistro10/17/2022
Ahh ok… and i can save the copy in an object ?
Mmtreit10/17/2022
The copy is like any other file, you can do whatever you like with it.
MMeistro10/17/2022
Thank you ! Maybe this would solve the problem ok thank you. I will test it again tomorrow …. Is there a way to make a file only openable with a specific app ?
Mmtreit10/17/2022
No
MMeistro10/17/2022
Kk
Mmtreit10/17/2022
Well Maybe If you run that app as a different user and set the DACL on the file to only allow that user access it's theoretically possible.
MMeistro10/17/2022
Becauz opening the csv with excel then save it and open finaly opening the file again with e.g Notepad++ breaks the file
Mmtreit10/17/2022
Breaks the file how? It's possible you have notepad++ configured to change the encoding or line endings or something.
MMeistro10/17/2022
Could you maybe help with my other question ?
Mmtreit10/17/2022
Normally opening a file in a text editor shouldn't change it unless you explicitly do something to change the file.
MMeistro10/17/2022
The excel does something when opening in excel This one as an example
AAccord10/19/2022
✅ This post has been marked as answered!

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
How to send multiple data sources to a view in asp.net 6? [Answered]Hey, So im learning asp.net 6. I have a page where i show products by giving a list to the view, ButUncaught Exception C++ hostfxr HandlingHi I have a C++ dll that I am using to host some dotnet assembly and normally things work but when sEntity Data Model WizardI was watching this tutorial: https://www.youtube.com/watch?v=1oGxPoTGl0U&ab_channel=TekTuition AroWhen to use EF queries, LinQ, or MySQLClientAttached is one of the Entity Framework (EF) queries I'm referring to (I'm not sure if this is what Process Checker [Answered]I'm creating an ""antivirus"" and I'm using a thread to check when a new process is started (but theArgumentNullException when argument is not nullI have this code: ```cs public class Config { [JsonProperty("token")] public string Token = "TOKWPF reusing the same template across multiple columnsThe following question https://social.msdn.microsoft.com/Forums/silverlight/en-US/f84e0efd-b1f2-4ab6Cascading DropDownI'm using MVC (.NET5) with EF and had this code to select a species on a View (to Create/Edit): ```cAssembly service findingHi, I am trying to find out if it's possible to get IServiceProvider, Microsoft IConfiguration or sohow do i submit a progra min vs to google classroomim trying to submit a project that's due to today but when i do submit it all i get is this and not WPF custom property not recognized by the compilerI have defined a custom property like below, it's in the namespace `CarApp`. It is supposed to repreEntity Framework DbContextOptionsBuilder.UseSqlServer() missing definitionI just installed the newest version of Entity Framework (6.0.9) and am inside my program.cs trying tDoes API manual nuget downloads come with the package dependencies?-WPF passing binding to a template from DataGridTemplateColumnSay, I have a template like this in resources, which I want to reuse for multiple columns, and whichBest way to implement a regex based lexer [Answered]In a regex lexer, you can loop over every pattern and do something like this: ```cs if (match.Successtring query in C Sharpi am trying to get values from 2 website links and assign them to a lable using visual studio one is there a convention for validating login sessions with MVC?Assuming I'm using ASP, ADO and .NET Say I want to construct a project to have several functions thUsing SQL db to create object ID or application?I have an application where my records in my DB need to have unique IDs. Should I leave this responsObject Initializers - To Parenthesize or Not To Parenthesize (that is the question)What is the difference between the object initializers on lines 1 and 2? In what situations should oHow do I move my mouse curser on screen?I went through most of stack overflow and some YouTube tutorials but didn't fins anything