|
Is it possible to add a custom property or attribute to any type of file? Say I want to add a property called "MySetting" with the value of "100" to MyFile.txt, then be able to see it in File => Right-Click => Properties => Detals. And also to be able to read that back in C#.
Is this possible in C#? I'm not really sure what to Google to research this?
Can anyone point me in the right direction?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I don't know about adding properties to files but you can add alternate file streams and store data in the alternate file stream for the file, I know it can be done with C/C++ but I have not done it for a while.
Whether you can get the properties in the file/right-click/properties/details properties I am not sure.
|
|
|
|
|
|
Thanks.
That postes says "
So this will only work with NTFS. ", so that may not work for what I need. That has me rethinking this.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Hi,
There is one existing property that might be sufficient for your needs: "Date Created" is a DateTime
which is set by Windows when the file gets created, and isn't modified afterwards. Internally it is stored as a 32-bit integer (often/always? with a resolution of 2 seconds), but Explorer won't show it as an integer, it will display numbers for year, day, hours, minutes, maybe month, typically not seconds.
So you could store a few small numbers in it: some range in the year, [1-31] in the day (assuming a long month), [0-23] in hours, [0-59] in minutes.
PS: when abusing Date Created, make sure there isn't any app (such as a backup utility) relying on the standard meaning of Date Created; I would hope such software relies on Date Modified, but I suggest you check that anyway.
modified 22-Mar-20 16:43pm.
|
|
|
|
|
The "100" in my post was just for illustrative porposes. I would want to write out any type of property, string, int, date/time, bool, etc
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Quote: hello gentlemen and thank you to you who bring me your help. I am almost at the end of my program and I have an update problem. I don't see any change in my stock.
I have no error when I validate but the quantity does not change in the access database
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
ref_prod = Convert.ToString(dataGridView1.Rows[i].Cells[0].Value);
Qte_prod = Convert.ToInt64(dataGridView1.Rows[i].Cells[1].Value);
using (OleDbCommand cmd3 = sql_con.CreateCommand())
{
cmd3.CommandText = "INSERT INTO Detail_commandes (com_det, ref_det, qute_det) VALUES (@com_det,@ref_det,@qute_det)";
cmd3.Parameters.AddWithValue("@com_det", TxtNunCmd.Text);
cmd3.Parameters.AddWithValue("@ref_det", ref_prod);
cmd3.Parameters.AddWithValue("@qute_det", Qte_prod);
sql_con.Open();
cmd3.ExecuteNonQuery();
sql_con.Close();
}
using (OleDbCommand cmd4 = sql_con.CreateCommand())
{
OleDbCommand QteStock = sql_con.CreateCommand();
QteStock.CommandText = "SELECT Quantite FROM Catalogue";
sql_con.Open();
int LastQteStock = Convert.ToInt32(QteStock.ExecuteScalar());
sql_con.Close();
cmd4.CommandText = "UPDATE Catalogue SET Quantite = @Quantite - @QteStc WHERE code_article = (@code_article)";
cmd4.Parameters.AddWithValue("@Quantite", LastQteStock);
cmd4.Parameters.AddWithValue("@QteStc", Qte_prod);
cmd4.Parameters.AddWithValue("@code_article", TxtRefProduit.Text);
sql_con.Open();
cmd4.ExecuteNonQuery();
sql_con.Close();
}
}
|
|
|
|
|
Once again: use the debugger. Find out what the numbers are, find out what the code-article value is. Then before you call ExecuteNonQuery to perform the update, check your DB for the exact current values using an Access query to find the specific rows.
Work out what the new row values should be for the numbers you looked at.
Step over the ExecuteNonQuery, and look at the same set of rows. Are they the new values?
We can't do any of that for you, we don't have your DB.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Understood sir and thank you for your promptness. i will keep looking
|
|
|
|
|
Sir I am happy because I was able to find a solution, its not easy because I really did not know how to go about it to see what is wrong. but I was able to post my request in a texbox to see what was wrong. I do not know my code is clean but the update is done.
How to find the code?
using (OleDbCommand cmd4 = sql_con.CreateCommand())
{
OleDbCommand QteStock = sql_con.CreateCommand();
QteStock.CommandText = "SELECT Quantite FROM Catalogue";
sql_con.Open();
int LastQteStock = Convert.ToInt32(QteStock.ExecuteScalar());
sql_con.Close();
string query = "UPDATE Catalogue SET Quantite = (@quantite - @QteStc) WHERE Code_article = (@code_article)";
cmd4.CommandText = query;
MessageBox.Show(query);
cmd4.Parameters.AddWithValue("@quantite", LastQteStock);
cmd4.Parameters.AddWithValue("@QteStc", Qte_prod);
cmd4.Parameters.AddWithValue("@code_article", ref_prod);
sql_con.Open();
cmd4.ExecuteNonQuery();
sql_con.Close();
}
|
|
|
|
|
Seriously, learn to use the debugger - it will show you exactly what is happening while your code is running. It lets you look at variables to check what they contain - and compare them to what you think they should contain - execute your code line by line, and a load of other things.
It's your biggest friend in development - and the place you should be spending most of your time!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Understood sir and thank you for your frankness. I will continue following your advice
|
|
|
|
|
the goal is to add and save later I can do it once when I want to do it for a second time I have an error: unable to find table 0, I must close the form and open it again so that I can do another one ... how to solve this problem without closing my form before?
private void BtnAjouter_Click(object sender, EventArgs e)
{
int total;
decimal total_achat;
if (TxtDesignation.Text == "" || TxtPrixUnitaire.Text == "" || TxtQteCmd.Text == "" || TxtQteStock.Text == "" || TxtRefProduit.Text == "")
{
MessageBox.Show("Rassurez vous que tous les champs ont bien été rempli.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (Int32.TryParse(TxtQteCmd.Text, out int value) && TxtRefProduit.Text != "")
{
int a = 0;
int b = 0;
int c;
int.TryParse(TxtQteCmd.Text.Trim(), out a);
int.TryParse(TxtQteStock.Text.Trim(), out b);
int.TryParse(TxtPrixUnitaire.Text.Trim(), out c);
if (a <= b)
{
total = a * c;
total_achat = 0;
try
{
setConnection();
sql_con.Open();
using (OleDbCommand cmd = sql_con.CreateCommand())
{
cmd.CommandText = "INSERT INTO Detail_temp (ref_det, qute_det, Designation, Prix_unitaire_HT, Prix_total_HT) VALUES (@ref_det,@qute_det,@Designation,@Prix_unitaire_HT,@Prix_total_HT)";
cmd.Parameters.AddWithValue("@ref_det", TxtRefProduit.Text);
cmd.Parameters.AddWithValue("@qute_det", TxtQteCmd.Text);
cmd.Parameters.AddWithValue("@Designation", TxtDesignation.Text);
cmd.Parameters.AddWithValue("@Prix_unitaire_HT", TxtPrixUnitaire.Text);
cmd.Parameters.AddWithValue("@Prix_total_HT", total);
cmd.ExecuteNonQuery();
DS.Reset();
DB.Fill(DS);
DT = DS.Tables[0]; (Problem is here):confused::confused:
dataGridView1.DataSource = DT;
cmd.Dispose();
sql_con.Close();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
Designation, Prix_unitaire_HT, Prix_total_HT) VALUES (@ref_det, @qute_det, @Designation, @Prix_unitaire_HT, @Prix_total_HT)";
try
{
LoadDB();
//ADDITIONNER UNE COLONNE DU DATAGRIDVIEW
for (int i = 0; i < dataGridView1.Rows.Count; i++) //Car tu fais une infériorité stricte
{
total_achat += Convert.ToDecimal(dataGridView1.Rows[i].Cells[4].Value);
}
TxtTotalCmd.Text = total_achat.ToString();//convertir total_achat en string^pour pouvoir l'afficher dans le textbox
vider();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
sql_con.Close();
}
finally
{
sql_con.Close();
}
}
else
{
MessageBox.Show("Veuillez verifier le stock du produit!!!");
}
}
}
}
|
|
|
|
|
Just what does DB have to do with anything?
DB.Fill(DS); It doesn't have any obvious relation to the Connection object, or to the Command - so why would you expect it to do anything useful?
Come on man, you need to start thinking here - instead of just copy'n'paste code from somewhere else and hoping it works!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
you may be right but i have declared its objects to display the info in the datagridview
private OleDbDataAdapter DB;
private DataSet DS = new DataSet ();
private DataTable DT = new DataTable ();
thanks for guiding me
|
|
|
|
|
Oh gawd, I only stopped banging my head on the desk yesterday ...
Stop and think.
Where are you getting the data from?
How does the data source connect to the DataSet?
How does the DataSet connect to the DataTable?
How does the DataTable connect to the DataGridView?
Any one of those links is wrong ... and you don't get data ...
Seriously man - get a book and start reading. You aren't helping yourself by trying and hoping - all you do is make yourself look ... umm ... pretty silly, he said as politely as he could manage.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
thank you sir i will read and get back to you because i feel like an idiot. I will review her and let you know.
|
|
|
|
|
Don't feel like an idiot, just learn the basics - because until you understand what you are doing, you are just whistling in the dark and hoping the noise attracts solutions rather than monsters ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
thank you sir because you give me courage I will review some court about it to find a solution I will come back to you even if I do not manage
|
|
|
|
|
sir you are right these lines were useless, they were useless ...
I just saw its The DataAdapter object serves as a link between a DataSet object and a data source.
A .NET data provider will use a DataAdapter object to fill data with a DataSet and then pass on the changes made to a data source.
|
|
|
|
|
Yes it does - but that doesn't mean that you create an instance and "magic happens"
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
yes sir i already did to change the datagridview
private void LoadDB()
{
setConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
string CommandText = "SELECT * FROM Detail_temp";
DB = new OleDbDataAdapter(CommandText, sql_con);
DS.Reset();
DB.Fill(DS);
DT = DS.Tables[0];
dataGridView1.DataSource = DT;
sql_con.Close();
}
maybe I'm wrong? but I did it to see my recordings in the datagridview
|
|
|
|
|
That's better - but in the code you showed to start with, you didn't do that, did you?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
yes sir and again thank you for your advice
|
|
|
|
|
Off topic, but why do you keep putting your messages in text tags?
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|