|
I remember I did this a while ago and never had any problems. I've just gone and checked and it turns out I used a delegate and BeginEnvoke() , although I've never tried to access the file imediatly after I got the callback. Maybe you could add a Thread.Sleep(1000); to make sure everything is finished - although it's not ideal.
Perhaps if you use a delegate like I did you won't have a problem, since this calls DownloadFile rather than the built in DownloadFileAsync , it's got to be worth a try at least.
private delegate void DownloadFile(string Address, string Path);
.
private void download(string Address, string Path)
{
System.Net.WebClient client = new WebClient();
client.DownloadFile(Address, Path);
}
.
private void internetDownload()
{
string address = ReadString();
string path = ReadString();
DownloadFile dload = new DownloadFile(download);
dload.BeginInvoke(address, path, new AsyncCallback(downloadCallback), dload);
}
.
private void downloadCallback(IAsyncResult result)
{
DownloadFile dload = result.AsyncState as DownloadFile;
dload.EndInvoke(result);
}
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Hello,
I've got very odd problem.
I use windows application to store files in data base (MySql) and then to extract this files from data base and save it on hdd. But when i save them back to hdd tihs files are 1Kb less from original file. When i insert pictures this 1kb obviously is not imported and the pictures is shown. But other files when try to be opened is corrupted or if they open some error message is shown.
So the code that i use to save file in DB is:
MySqlConnection con = new MySqlConnection("SERVER=localhost;" +
"DATABASE=db;" +
"UID=user;" +
"PASSWORD=root;");
MySqlDataAdapter da = new MySqlDataAdapter("Select * From test", con);
MySqlCommandBuilder MyCB = new MySqlCommandBuilder(da);
DataSet ds = new DataSet("test");
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
FileStream fs = new FileStream(@"C:\image.rar", FileMode.OpenOrCreate, FileAccess.Read);
byte[] MyData = new byte[fs.Length];
fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
da.Fill(ds, "test");
DataRow myRow;
myRow = ds.Tables["test"].NewRow();
myRow["id"] = "12";
myRow["blobdata"] = MyData;
ds.Tables["test"].Rows.Add(myRow);
da.Update(ds, "test");
con.Close();
The code that extract files from database and save them to hdd is:
MySqlConnection con = new MySqlConnection("SERVER=localhost;" +
"DATABASE=db;" +
"UID=user;" +
"PASSWORD=root;");
MySqlDataAdapter da = new MySqlDataAdapter("Select * From test where id = 12", con);
MySqlCommandBuilder MyCB = new MySqlCommandBuilder(da);
DataSet ds = new DataSet("test");
byte[] MyData;
da.Fill(ds, "test");
DataRow myRow;
myRow = ds.Tables["test"].Rows[0];
MyData = (byte[])myRow["blobdata"];
int ArraySize;
ArraySize = MyData.GetUpperBound(0);
FileStream fs = new FileStream(@"C:\Data\image.rar", FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(MyData, 0, ArraySize);
fs.Close();
Thanks!
King Regards!
countNazgul
modified on Thursday, July 3, 2008 10:42 AM
|
|
|
|
|
countnazgul wrote: byte[] MyData = new byte[0];
What the purpose of that?
countnazgul wrote: int ArraySize = new int();
Whats the purpose of that?
countnazgul wrote: System.Convert.ToInt32(fs.Length-1)
Whats the purpose of that?
Now, remove all that useless crap from your code, so we can at least read and understand it...
|
|
|
|
|
Ok. I remove the piece of code
King Regards!
countNazgul
|
|
|
|
|
Do U Check To See if The Data (file in your case)
was received Successfully and Fully??
there are lots of events and Methods in (MySql/ODBC/OLEDB/SQLserverDataAdapter)
Like the FillError Event
Have Fun
Never forget it
|
|
|
|
|
Yes file was OK.
But i find another solution that extract my files without a problem.
Here is and the code:
MySqlConnection Conn = new MySqlConnection("SERVER=localhost;" +
"DATABASE=db;" +
"UID=user;" +
"PASSWORD=root;");
MySqlCommand Cmd = new MySqlCommand("Select * From test where id = 19", Conn);
Cmd.CommandType = CommandType.Text;
Conn.Open();
MySqlDataReader Reader = Cmd.ExecuteReader(CommandBehavior.CloseConnection);
FileStream FStream = null;
BinaryWriter BWriter = null;
byte[] Binary = null;
const int ChunkSize = 100;
int SizeToWrite = 0;
MemoryStream MStream = null;
while (Reader.Read())
{
FStream = new FileStream(@"c:\Data\Nomenclature123.xls", FileMode.OpenOrCreate, FileAccess.Write);
BWriter = new BinaryWriter(FStream);
Binary = (Reader["blobdata"]) as byte[];
SizeToWrite = ChunkSize;
MStream = new MemoryStream(Binary);
for (int i = 0; i < Binary.GetUpperBound(0) - 1; i = i + ChunkSize)
{
if (i + ChunkSize >= Binary.Length) SizeToWrite = Binary.Length - i;
byte[] Chunk = new byte[SizeToWrite];
MStream.Read(Chunk, 0, SizeToWrite);
BWriter.Write(Chunk);
BWriter.Flush();
}
BWriter.Close();
FStream.Close();
}
FStream.Dispose();
Thank You gays for responses!
King Regards!
countNazgul
|
|
|
|
|
countnazgul wrote: Thank You gays for responses!
I'm straight, thank you.
|
|
|
|
|
I've been at this for a week now and i've only managed to connect to an open sharepoint site (public), but when it comes down to connecting to a password-protected site it becomes a pain and I can neither find nor get any methods to work without exceptions. Any help?
Thanks mates!
-Kevin
Sharp Business Systems
|
|
|
|
|
How to Print a windows form using C# 2008.
The form is just like an Id Card.
How to do that. could you help me.
|
|
|
|
|
|
|
i'm working with DGV and found a little problem that is DGV losses selection when it get clicked before releasing the mouse button, e.g. i have selected 5 rows and if i click on a already selected row then other selected rows get unselected before releasing the mouse button, what i want is, when i click on a already selected row then other selected rows should be keep selected until i release the mouse button like ListView, is there anyway to accomplish this task ?
thanks
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
You are holding down the Control key when selecting?
|
|
|
|
|
no, ok once try it on ListView, i exactly want that, in LV focus do not loss from other selected items until mouse button release
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
At present I have a filesystemwatcher which monitors a folder for the activities of files in that folder.
Now I would like to monitor other folders too.
Can the filesystemwatcher monitor several folders at the same time?
Thanks
|
|
|
|
|
only if all folders are subfolders of the selected folder or drive
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Hi,
I want to implement the Linked list, hash table functionality in .NET without using the collection classes, assuming they are not present.How Can I achieve this?
Regards,
Srinu
|
|
|
|
|
srinivas0099 wrote: How Can I achieve this?
Buy a book on algorithms...
|
|
|
|
|
O sorry, wasnt my previous answer sufficient? Would you like me to write all the code for you?
|
|
|
|
|
Thank you for your reply Leppie
if you have sample code then only....
other wise give me some reference books name..
I am very thank full if you provide me the code..
Regards,
Srinu
|
|
|
|
|
srinivas0099 wrote: if you have sample code then only....
No I dont.
srinivas0099 wrote: other wise give me some reference books name..
Google: Data structure and Algorithms in C#. It's not hard. I know there are at least 3 sites that will provide you all the code. But the first step for you is to try and do it yourself. We dont spoonfeed. If you have a specific problem, we will help.
|
|
|
|
|
|
|
How could they not be present ? Under what bizarre circumstance do you expect only half the .NET library to be installed ?
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
What is CS education except reinventing the wheel.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|