|
JohnsonDesouza wrote: "The process cannot access the file 'C:\\Temp\\FileLockTest1.txt' because it is being used by another process."
This is because the file is opened by "exclusiveWriter" object and has not closed yet. You need to close it before opening the file for reading.
FileStream exclusiveWriter = new FileStream(@"C:\Temp\FileLockTest1.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
for (byte counter = 0; counter < 100; counter++)
{
exclusiveWriter.WriteByte(counter);
}
exclusiveWriter.Close();
FileStream sharedReader = new FileStream(@"C:\Temp\FileLockTest1.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
sharedReader.Seek(0, SeekOrigin.Begin);
for (byte counter = 0; counter < 100; counter++)
{
Console.WriteLine(sharedReader.ReadByte());
}
sharedReader.Close();
Console.ReadLine(); You can also consider to use using block.
|
|
|
|
|
JohnsonDesouza wrote: How can I read the files?
To be clear here - you cannot. That's what exclusive lock means. Someone has shown how to remove the lock in C#, if this is a COM C++ program, you need to change that code to close the file.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
yes you can read log files from ongoing processes provided they are coded appropriately.
you'll have to change the code: by default a file writer opens the file denying the world to
see the file's content for as long as it is open. IMO you have three options:
1.
have the writer close the file when done; from then on any app can read the file.
2.
have the writer perform open-for-append, append, close for every write it wants to execute.
that way readers will succeed most of the time. This is my way of implementing logging.
It is not great performance wise, but it works great.
3.
have the writer open the file with FileShare.Read i.e. have it allow others to read while
the writer has the file open. There are two caveats:
a) there is some buffering going on, so the writer should perform the right Flush() operation
to force the data out, making it available for the reader(s).
b) the file may be in an intermittent state (not fully consistent) when the reader gets data
at the same time the writer is adding to it. So readers should be tolerant.
|
|
|
|
|
Hi Everyone,
I have a statusstrip control on my form and how do I show some text on it. I tried the text property but nothing is visible on the form. kindly help. I know this question may sound silly to some but then I am just a beginner
Regards,
LG
lgatcodeproject
|
|
|
|
|
Hi,
The status strip is a sort of menu / toobar. You have to add something to it,
like a ToolStripStatusLabel, and then assign your text to that label.Text.
In the forms designer, if you left click on the statusStrip (in the form),
you should see a little box with an arrow. Left click on that, and you get
a menu of items you can add (label, progressBar, dropDownButton,
splitButton). Click on one to get the item added.
Then go to the properties of the item you added and assign the name. I hope this would be helpful.
Regards,
Vinay
ComponentOne LLC.
www.componentone.com
|
|
|
|
|
Hello Vinay,
Thanks, it solved my purpose. Can we configure some other items (other than those provided in the dropdown)to this status strip in runtime?
Regars,
LG.
lgatcodeproject
|
|
|
|
|
One of my articles might be able to help you their: Custom ToolStrip Renderers[^]. You are able to add other controls using the ToolStripControlHost. You can browse most of the classes that can manipulate the ToolStrips by using the Object Browser.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
I am trying to add propertyitem dynamically to property grid.
For example If I want to add a property Item Like a text box which takes "String name" as variable how to add dynamically to property Grid?
I can do the following to add the "name" text box at static design time:
public class PropertyGridProcessDesigner
{
[Editor(typeof(PropertyGridProcessDesigner), typeof(System.Drawing.Design.UITypeEditor))]
public string Name
{
get { return name; }
set { name= value; }
}
}
But how to achieve the same above thing at run time ?
Do we need to create dynamic classes to add Property Item ?
If so, can anyone please share any information you have ?
Thanks,
rajan
|
|
|
|
|
|
// Save the stream to disk
System.IO.FileStream newFile = new System.IO.FileStream(Server.MapPath(sSavePath + sFilename), System.IO.FileMode.Create);
newFile.Write(myData, 0, myData.Length);
newFile.Close();
TextWriter tw = new StreamWriter(Server.MapPath("Images/Saved Images/info.txt"));
// write a line of text to the files
tw.WriteLine(txtFName.Text + " " + txtLName.Text + " " + IDTextBox.Text + " " + sSavePath + sFilename);
// close the stream
tw.Close();
it works but whenever i try to upload 2 or more files/images... it will just overwrite the exisiting texts.. how do i make it such that it will create a new line each time i upload an image upon the existing ones?
|
|
|
|
|
Do you mean you want to open an existing file and APPEND data to the end of it?
|
|
|
|
|
Thomas Toh wrote: System.IO.FileMode.Create);
This creates a new file, like it says. Use Append to add to an existing file.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
File.AppendText() seems to be the easiest way to get what you want.
|
|
|
|
|
Hi all,
Basically i have 2 question in this message.I am using DataGridViewComboBoxColumn to insert a ComboBox into my datagridview.Code as below:
dataGridView1.Columns.Remove("Seqence_Number"); <----remove the original column first before add the combo box
DataGridViewComboBoxColumn dgvComboBox = new DataGridViewComboBoxColumn();
dgvComboBox.DataPropertyName = "Seqence_Number";
dgvComboBox.HeaderText = "Sequence (Stage)";
dgvComboBox.DropDownWidth = 100;
dgvComboBox.Width = 100;
dgvComboBox.MaxDropDownItems = 10;
dgvComboBox.FlatStyle = FlatStyle.System;
dsTemp = singleton.ProdetailsDataset.Copy(); <-----dataset will copy from my singleton class
dgvComboBox.DataSource = dsTemp.Tables[0];
dgvComboBox.ValueMember = "Stage_Name";
dgvComboBox.DisplayMember = "Stage_Name";
dataGridView1.Columns.Insert(1,dgvComboBox);
The first question is, how can i display more than one value member in ComboBox?
The second qeustion is, how can i do a selected event for that ComboBox in datagridview? what i wanna do is when user select the value in ComboBox, some event will fire to validate the value which selected by user.
Any tips are welcome,
Thanks in advance
|
|
|
|
|
Hi,
1) Concatnate the two column values (in a query) and assign as a value member.
2) You can use "EditingControlShowing" event to access the "SelectedIndexChanged" event for combobox cell.
Here is the Code Snipet:
private void Form1_Load(object sender, EventArgs e)
{
this.dataGridView1.EditingControlShowing += new System.Windows.Forms.DataGridViewEditingControlShowingEventHandler(this.dataGridView1_EditingControlShowing);
}
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox ctl = e.Control as ComboBox;
if(ctl!=null)
ctl.SelectedIndexChanged+=new EventHandler(ctl_SelectedIndexChanged);
}
private void ctl_SelectedIndexChanged(object sender, EventArgs args)
{
MessageBox.Show("Selected Index Changed Event");
}
Thanks,
Gopal.S
|
|
|
|
|
Hi Gopal.S
Thanks for your suggestion. I am just figure out how to do it, but seem you have a better suggestion
1) I just simple Concatnate the columns after i get the dataset, something like below:
string s = dsTemp.Tables[0].Rows[1][2].ToString() + dsTemp.Tables[0].Rows[1][3].ToString();
2) I am using CellEndEdit ,as below;
this.dataGridView1.CellEndEdit += new DataGridViewCellEventHandler(dataGridView1_CellEndEdit);
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
string cellvalue;
if (e.ColumnIndex == 1)
{
cellvalue = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
if (cellvalue != null && cellvalue != "")
{
}
}
I will try you suggestion too, Thanks ![Laugh | :laugh:](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_laugh.gif)
|
|
|
|
|
Member Function Pointers usage on class instances:
Class A is derived from Class ZZZ. Class A has a member function A::ftnOnA
Class B is derived from Class YYY.
Class A instantiates Class B
Could Class A pass a member function pointer to Class B and then Class B be able to call A::ftnOnA? (Like a call back procedure)
Can anyone please help me?
|
|
|
|
|
You can set up a delegate to achieve this.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello all! I have a college project due tomorrow and I am in dire need of some assistance! The project requires that I create a plain windows form with six controls on it; I have chosen six buttons. Form2 will be the startup form, will have a combobox and a DataGridView (I am using a richTextBox right now, but will change that once the rest works). The names of the controls from Form1 populate the combobox in Form2. By selecting one of the controls from the combobox, all of that controls' properties are then listed in the DataGridView.
I have most of it working, but I cannot get the value for each property using the GetValue(object, object[] index) method. I have tried all that I can think of, but cannot get it to work. The code that I have for Form2 is as follows:
Here, the main problem is on the bottom line of code. I have commented there.
public partial class Form2 : Form
{
//Declares an Array of type Controls:
Control[] controls;
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
//Creates an instance of Form1:
Form1 myForm = new Form1();
//Initializes the Control[] by calling the getControls() method on Form1:
controls = myForm.getControls();
//Adds the Control names to the ComboBox:
foreach (Control c in controls)
{
myCboBox.Items.Add(c.Name);
}
}
private void myCboBox_SelectedIndexChanged(object sender, EventArgs e)
{
//creates an int to hold the selected index:
int index = myCboBox.SelectedIndex;
//creates a type variable:
Type t = controls[index].GetType();
//clears any previous entries:
richTextBox1.Clear();
foreach (PropertyInfo prop in t.GetProperties())
{
//Here, the GetValue method will not work! I have tried passing everything that I can think of to it
//and still it will not work. It keeps telling me that target object does not match.
//Please help.
richTextBox1.Text += "\n" +
prop.Name + "\t\t:" + prop.GetValue(t, null);
}
}
}
"If you don't know where you're going, you'll probably end up somewhere else." Yogi Berra
|
|
|
|
|
Perhaps the first form should have a public property that yields a list of the names of the controls?
|
|
|
|
|
The first form does. It has an array of Controls that are populated by the Controls that are on it. There is a method, GetControls() that returns the array of Controls. Form2 then loops through that array and populates the comboboxlike so:
foreach (Control c in controls)
{
comboBox1.Items.Add(c.Name);
}
I know that this is working because when the code is ran, if you take away the faulty attempt to call the GetValue(object, object[] index) method, all of the property names are properly displayed in the richTextBox.
I need to know the proper way to call the GetValue(object, object[] index) method to get the property values, given the way that I am going about the logic.
Thanks.
"If you don't know where you're going, you'll probably end up somewhere else." Yogi Berra
|
|
|
|
|
MrColeyted wrote: richTextBox1.Text += "\n" +
prop.Name + "\t\t:" + prop.GetValue(t, null);
You are trying to find the property value from the type, you have tried to get it from the object itself
richTextBox1.Text += "\n" +
prop.Name + "\t\t:" + prop.GetValue(controls[index], null);
*jaans
|
|
|
|
|
My friend, I could kiss you! Thank you so very much. That did it!
"If you don't know where you're going, you'll probably end up somewhere else." Yogi Berra
|
|
|
|
|
Hello all,
I am looking for a program that will generate C# classes from a xsd schema.
A. I need it to be able to generate separate .cs files for the schemas that are are imported.
B. I need it to generate partial classes and would like it to generate generic collections.
C. I need it to be a free, downloadable program.
I have looked at the following tools:
1. xsd.exe - Does not generate multiple files.
2. XSDObjectGen - Does generate multiple files (given that the schemas have different namespaces), will generate partial classes, but it uses ArrayLists for it's collections (if it's 2.0 aware, why on earth would it generate ArrayLists?).
3. XSDClassGen - Does generate Generic collections, but does not generate multiple files.
4. CodeXS - Is an internet only tool.
Thanks in advance.
|
|
|
|
|
I found another one that doesn't do what I want.
It's called 'Dingo'. The author claimed that it's highly extensible.
When I tried to compile the classes it generated, they didn't compile.
It also doesn't generate partial classes unless you write a plugin for it.
|
|
|
|