|
Thanks. Forgot about unlocker. Will try tommorow at work.
Regards,
Matjaž
|
|
|
|
|
Waiting for results
|
|
|
|
|
Goodmorning in a new day.
I've had my files locked, because i was trying to rewrite the same file. Unlocker didnt show anything. Thought i could change the output to the same filename as input.
Ok, fixed this.. but now im trying to get this thing into a loop. I have a listbox with filenames/paths. Looks like this:
for (int c = 0; c < listBox1.Items.Count; c++)
{
listBox1.SelectedItem = c;
int length;
byte[] bt = new byte[1024];
FileStream input = new FileStream(listBox1.Text, FileMode.Open);
FileStream output = new FileStream(listBox1.Text + ".new", FileMode.Create);
BinaryReader rd = new BinaryReader(input);
BinaryWriter rw = new BinaryWriter(output);
rd.Read(bt, 0, 55);
while (true)
{
length = rd.Read(bt, 0, 1024);
if (length == 0) break;
rw.Write(bt);
}
rd.Close();
rw.Close();
input.Close();
output.Close();
}
Well, it goes only through the first item (that i manualy selected). Where seems to be the problem? I'm focused at that "break;", but i guess that only breaks while loop? or it also breaks my for loop...
Thanks.
Regards,
Matjaž
|
|
|
|
|
You don't need listBox1.SelectedItem = c; Just access i-th item like this: string text =listbox1.Items[i].ToString();
|
|
|
|
|
Ok. Fixed and working. Thanks. If u want, take a look at my new question, regarding tiff images and going through pages of tiff.
Thanks and have a nice, successful day
Regards,
Matjaž
|
|
|
|
|
Glad to help you
I already did but I unfortunately I don't know how to do it. If you want vote for the answers I have given to you
|
|
|
|
|
If it helps... i'll vote for some
Regards,
Matjaž
|
|
|
|
|
It just shows appreciation from you and works as an encouragement. Thank you
|
|
|
|
|
i used the code like this to pervent overflow:
string deletethis = "";
using (var reader = new StreamReader(@"C:\<>\U2\" + props["File"].Replace("%20", " ")))
{
deletethis = reader.ReadLine();
deletethis = deletethis + reader.ReadLine();
deletethis = deletethis + reader.ReadLine();
deletethis = deletethis + reader.ReadLine();
deletethis = deletethis + "ream" + Environment.NewLine+""+Environment.NewLine;
reader.Close();
reader.Dispose();
};
byte[] bytes = Encoding.ASCII.GetBytes(deletethis);
byte[] x = File.ReadAllBytes(@"C:\<>\U2\" + props["File"].Replace("%20", " "));
byte[] temp = new byte[x.Length - bytes.Length];
Int64 tempx = 0;
for (Int64 i = bytes.Length; i < x.LongLength; i++)
{
temp[tempx] = x[i];
tempx++;
}
File.WriteAllBytes(@"C:\<>\U2\" + props["File"].Replace("%20", " "), temp);
|
|
|
|
|
1. Use BinaryReader and BinaryWriter to read and write file in binary mode.
2. Don't read the whole file at once. If the file is to large you might get an exception.
|
|
|
|
|
Hi all,
I have to Disable 'Start' button untill the thread completes.
btn_Start_Click(object sender, EventArgs e)
{
Thread th = new Thread(new ThraedStart(Download));
th.Start();
if (th.ThreadState == ThreadState.Running) // Here i am Disabling
btn_Start.Enabled = false;
// But where i have write logic for Enabling the Button
//like if(th.ThreadState==ThreadState.Stopped) btn_Start.Enabled = true;
}
public void Download()
{
// Here i wrote logic for downloading files.
}
Please suggest me how to Disable Button until thread completes.
Thanks in Advance
|
|
|
|
|
btn_Start_Click(object sender, EventArgs e)
{
Thread th = new Thread(new ThraedStart(Download));
th.Start();
if (th.ThreadState == ThreadState.Running)
btn_Start.Enabled = false;
}
public void Download()
{
this.Invoke((MethodInvoker)delegate
{
btn_Start.Enabled = true;
});
}
|
|
|
|
|
Hi,
Thanks for your suggestion. But i already tried that one. But its giving Cross thread eroor.
Bcz, Download is running under thread th, where as btn_Start is running as main thread, so you can't change status of button of main thread in derived thread(th).
Is there any alternative .
Thanks in advance.
|
|
|
|
|
sekhar.k wrote: But its giving Cross thread eroor.
I know. I have edited the post. You need to use Invoke/BeginInvoke. Check my first reply.
|
|
|
|
|
Enable it in the last line of code in your thread
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
Hi,
Thanks for your suggestion. But i already tried that one. But its giving Cross thread exception.
Bcz, Download is running under thread th, where as btn_Start is running as main thread, so you can't change status of button of main thread in derived thread(th).
Is there any alternative .
Thanks in advance.
|
|
|
|
|
It seems to me that you don't understand what a thread is. The start method will execute COMPLETELY, and the thread will go off and do it's work. Use a WorkerThread and have it's completed event enable your button.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hi,
thanks for your suggestion. I will try it.
|
|
|
|
|
|
Hello,
How to create stored procedure dynamically in c#.net. Because
some of my requirements needs such a situation. Please help with some example code.
Thanks and Regards
|
|
|
|
|
Just execute the statements as you did for normal query. But why you need to create a SP run time? That doesn't make any sense.
|
|
|
|
|
Hi Navaneeth,
Because of requirement, I need to create tables and stored procedures at runtime. This is created at runtime because it is managed on clients system or database server during installation of application.
Thanks for reply.
|
|
|
|
|
Well, Try the following code
string query = @"CREATE PROCEDURE SampleProcedure
AS
BEGIN
SELECT 'From Sample Procedure'
END";
using (SqlConnection connection = new SqlConnection(@"YourConnectionString"))
using (SqlCommand command = new SqlCommand(query,connection))
{
connection.Open();
command.ExecuteNonQuery();
} If you have many SQL statements to be executed, I'd put it in a file and read from there to execute.
|
|
|
|
|
Could you please explain? What is the problem in this create procedure QueryString.
"CREATE PROCEDURE test.dbo.Operator @MasterField varchar(300) AS SELECT SubOperatorField FROM SubOperatorInfo WHERE MasterField=@MasterField AND departField IS NOT NULL AND SubOperatorField=somevalue";
this querystring fires an exception i.e.:-
'CREATE PROCEDURE' does not allow specifying the database name as a prefix to the object name. Must declare the variable '@MasterField'.
|
|
|
|
|
try taking the database name out of the name of the procedure
You should be already in the context of the database, e.g the SqlConnection is already connected to "test".
James
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|