|
It is the only way, unless you want to write your own file copy class with a dialog that shows progress.
Post the code that your using, including the DllImport, to call the function so we can figure out what your doing wrong. You don't need to supply a callback to the function. If you don't supply one (pass in null in that parameter), the CopyFileEx function will display it's own progress dialog.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi, thats exactly what i figured out i few days before. I developed a filebrowser. And it also contains a dialog for copying files and it shows the progress. Look to class copydialog of the file clipboard.cs.
Download from www.slenders.be
It also contains examples for moving files, copying folders, etc.
Just take a look
Jonathan Slenders
|
|
|
|
|
I'm having some problems getting wsdl.exe to run (properly) on some wsdls that I have. I am trying to create a client using C# that uses these webservices that someone else created. I think the problem I am having has to do with the webservices were created using Java and the standard they use for WSDLs are a little different from the standards microsoft uses. Does anyone know of a converter that will take a Sun/IBM WSDL and convert it to a WSDL that microsoft can use?
Thanks for your help.
|
|
|
|
|
I have a question about how to get certain data from my dataset. I am trying to get rows from one table that have certain child relations to appear.
I have a table called stories. The table stories has 5 child relations. One relation goes to each table. One table, called categories, is a child of stories. The categories table has three columns.
1. id int
2. storyid string
3. catid int
id is just a sequential number as the primary key of the table. storyid is the number of the id of the story this entry in the category table belongs to. catid is a number that corresponds to a entry in the categoryinfo table.
So my idea is to select certain stories that have a given catid. So, for example, say I want to see all the stories that have 5 as a catid. What I am trying to do now is to use the select method available to tables. So the few lines of code are this:
//Notitia is the name of the class for the typeddataset I use.
storiesfiltered = new Notitia.StoriesDataTable();
string fil = "Child(storiescategories).catid = 5";
DataRow[] drows = stories.Select( fil );
foreach( DataRow row in drows )
{
storiesfiltered.ImportRow( row );
}
However, whenever I run this code i get an error at the stories.select line and the error says "Cannot interpret token 'Child' at position 1." I'm not sure why I get this error. I checked msdn about expressions and that is how it told me to write expressions involving relations to child tables.
If anyone has any ideas why that doesn't work or another way to do it I would appreciate the help. Thanks.
Paul Rogero
|
|
|
|
|
Create a typed DataSet using VS.NET and create relationships between the tables. You can access these relationships in code using the DataRelation . You specify this DataRelation using DataRow.GetChildRows . This is much faster and less prone to error than using just DataTable.Select .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Hi,
I am getting a root element is missing when I try to read in the xml diffram from file. Also one key note I am using the compact framework which doesn't support Typed datasets.
Heres the code that I am trying out:
<br />
<br />
public static DataSet GetMyXmlDS(string sXmlFileName, string sPath ) <br />
{<br />
string sFileName = sPath + @"\MidnightData.xml";<br />
string sFileName2 = sPath + @"\MidnightRead2.xsd";<br />
<br />
<br />
DataSet IpacDS = new DataSet("Table1");<br />
<br />
try<br />
{<br />
<br />
SqlConnection myCon = new SqlConnection();<br />
myCon.ConnectionString = sCon1;<br />
SqlDataAdapter da = new SqlDataAdapter(@"Select * From MidnightReadings WHERE MR_Date = '12/1/2003'", myCon);<br />
<br />
da.Fill(IpacDS);<br />
<br />
FileStream myFileStream = new System.IO.FileStream<br />
(sFileName, FileMode.OpenOrCreate);<br />
<br />
XmlTextWriter myXmlWriter = <br />
new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);<br />
<br />
IpacDS.WriteXml(myXmlWriter, XmlWriteMode.DiffGram);<br />
IpacDS.WriteXmlSchema(sFileName2);<br />
<br />
<br />
XmlTextReader myXmlTextRead = <br />
new System.Xml.XmlTextReader(myFileStream);<br />
<br />
<br />
IpacDS.ReadXml(myXmlTextRead);<br />
<br />
return IpacDS;<br />
<br />
}<br />
catch (SqlException e) <br />
{<br />
string errorMessage = "Message: " + e.Message + "\n" +<br />
"Source: " + e.Source + "\n" +<br />
"State: " + e.State + "\n" +<br />
"Procedure: " + e.Procedure + "\n";<br />
MessageBox.Show(errorMessage,"Error in DataCon");<br />
<br />
return IpacDS;<br />
}<br />
catch (XmlException xe) <br />
{<br />
string errorMessage = "Message: " + xe.Message + "\n" ;<br />
MessageBox.Show(errorMessage,"Error in DataCon");<br />
<br />
return IpacDS;<br />
} <br />
<br />
}<br />
<br />
Xml dataset :
<br />
<br />
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><br />
<Table1><Table diffgr:id="Table1" msdata:rowOrder="0"><br />
<MR_ID>110</MR_ID><br />
<MR_Date>2003-12-01T00:00:00.0000000-05:00</MR_Date><br />
<Coal_Feeder_Tot>690058</Coal_Feeder_Tot><br />
<Coal_Silo_Level_Prct>73</Coal_Silo_Level_Prct><br />
<Coal_Barn_Inv_Prct>25</Coal_Barn_Inv_Prct><br />
<Limestone_Feed_Total>171316</Limestone_Feed_Total><br />
<LS_Silo_Level_Prct>70</LS_Silo_Level_Prct><br />
<Ammonia_Totalizer>388974</Ammonia_Totalizer><br />
<Prop_to_Burn_Totalizer>14629</Prop_to_Burn_Totalizer><br />
<TwentyFourHr_SO2_Reduct>92</TwentyFourHr_SO2_Reduct><br />
<Limestone_Received>40800.37</Limestone_Received><br />
<Ammonia_Received>0</Ammonia_Received><br />
<Prop_Received>9004</Prop_Received><br />
<Est_hours_Dry_Oper_Hours>0</Est_hours_Dry_Oper_Hours><br />
<LAB_Sulfur_Content_Prct>2.13</LAB_Sulfur_Content_Prct><br />
<LAB_High_Heat_Val>6833</LAB_High_Heat_Val><br />
<CEMS_SO2_Daily_Avg>549</CEMS_SO2_Daily_Avg><br />
<Raw_Water_Pump_Meter>15795967</Raw_Water_Pump_Meter><br />
<Reservoir_Level>1844</Reservoir_Level><br />
<Date_Rec_Added>2003-12-08T08:47:15.0000000-05:00</Date_Rec_Added><br />
</Table></Table1><br />
</diffgr:diffgram><br />
<br />
Now what gets me is that as you can see in the code. I am writing the dataset to file and a schema to file. Then I turn right around and try reading it in but fails on the ReadXML statement. I have tried reading in the Schema file into dataset first and then without reading in schema. Any ideas?
Thanks,
JJ
|
|
|
|
|
You might want to Flush and Close the XMLTextWriter before you turn around and try and read the file it wrote. You'll have to reopen the FileStream for Read after you do this.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
What is the easiest what to load 4000 rows into a SQLSever db from a C# program? The C# rows are in an ArrayList. And the "scheme" is very simple
[string, date, decimal, decimal, integer].
I’m looping threw the array, right now, and doing an insert for each row but I’m wondering if there is some way I can do this in bulk? I think BCP would be overkill in this case, so, I'm just wondering if there is something in ADO.NET that might handle a "large" number if inserts.
|
|
|
|
|
BCP would definitely be the best way. You could write out the file and execute BCP on it.
You could also use parameters inserts. Construct your SqlCommand with parameters for the fields. When enumerating over your ArrayList , set the SqlParameter.Value for each field and call SqlCommand.ExecuteNonQuery . BCP will probably be faster, though.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You can also just batch the insert statements together and execute them all at once, or in smaller batches of 10 or so. Just seperate the statements with ;
If you don't kill me you will only make me stronger
That and a cup of coffee will get you 2 cups of coffee
|
|
|
|
|
Does anyone know how to get a hot key onto a tab page? I tried the standard of putting "&" in front of the letter I want to be the hotkey but it just puts the "&" into the text on the tab itself. I have been digging around and have not come up with anything yet. There must be an easy way to do this... does anyone have any ideas?
|
|
|
|
|
Handle the KeyDown event of the TabControl and use something like this:
private void tabControl1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Modifiers == Keys.Alt)
{
switch (e.KeyCode)
{
case Keys.G:
tabControl1.SelectedIndex = 0;
break;
case Keys.S:
tabControl1.SelectedIndex = 1;
break;
}
}
} Of course you'd use the Keys enumeration for the tab. If you want to make this localizable, you could do something like localize the TabPage.Tag property and enumerate through them. If that key was pressed, select that TabPage . There's many other ways you could accomplish this as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hello,
i'm wondering how to deploy an assembly without using setup wizard. Can i got an simple program written in C# or VB.net that is used for deploying an other assembly.
|
|
|
|
|
Just copy it. If you want it globally available, install it into the GAC after copying (use gacutil.exe /i assemblyname.dll ). If you want a private assembly (only for use with the application), copy it to the application's installation directory (same directory as the .exe) or into a private path (configured in the .config).
Read How the Runtime Locates Assemblies[^] in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi all,
I have a DateTime field in a dataset wich I display in a Datagrid. Since I would like to show only the Time part of datetime I'd like to know how this could be done.
I've been trying somethings on Binding.Format, using a Converter so that when the data is loaded from the dataset into the datagrid i can change the datetime's format in order to exhibit only the time part.
Can this be done this way, or do I need to workarround (adding a column, or iterating trough the datagrid)?
Thanks for your attention,
Anfernius
|
|
|
|
|
Just set the DataGridColumnStyle.Format to a time format string, like t , T , or a custom format which is documented in the DateTime.ToString methods.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks, that worked fine (sorry though, it was a dumb question)
Just out of curiosity, while reading on binding.format event occured to me that it could be possible to store a time interval in ticks in the dataset and then convert it to a readable format like "12:12 12" while filing the datagrid.
Could this be done by binging a converter to a specific column in the datagrid...
bah! just wondering....
Thanks,
Anfernius
|
|
|
|
|
Forget using a TypeConverter . All you need is an implementation of IFormatProvider , that you assign to DataGridColumnStyle.FormatInfo . This only works for types that implement IFormattable , however, a bug that I have reported to the .NET team.
See my article, Custom String Formatting in .NET[^] for more information about formatting (namely the IFormatProvider ) and links to more information in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a worker thread that is updating a Label on a dialog. The Thread responds correctly to the button clicks when the program is running. But when I close the dialog and attempt to stop the worker thread from the Closing() event handler the thread will not stop. I've mocked up and example:
private bool RunThread=true;
private delegate void ThreadMessageDelegate(string Mess);
private Thread MessageThread=null;
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void LabelThread()
{
if(lbThreadLabel.InvokeRequired)
lbThreadLabel.Invoke(new ThreadMessageDelegate(ShowThreadMessage),new object [] {"Thread Started"});
Thread.Sleep(1000);
while(RunThread)
{
if(lbThreadLabel.InvokeRequired)
lbThreadLabel.Invoke(new ThreadMessageDelegate(ShowThreadMessage),new object [] {null});
Thread.Sleep(50);
}
if(lbThreadLabel.InvokeRequired)
lbThreadLabel.Invoke(new ThreadMessageDelegate(ShowThreadMessage),new object [] {"Thread Stoppped"});
}
private void ShowThreadMessage(string Mess)
{
if(Mess==null)
lbThreadLabel.Text=DateTime.Now.ToString();
else
lbThreadLabel.Text=Mess;
}
private void Form1_Load(object sender, System.EventArgs e)
{
MessageThread = new Thread(new ThreadStart(LabelThread));
}
private void runtimer_Tick(object sender, System.EventArgs e)
{
switch (MessageThread.ThreadState)
{
case ThreadState.Running:
lbThreadState.Text="Running";
break;
case ThreadState.Suspended:
lbThreadState.Text="Suspended";
break;
case ThreadState.WaitSleepJoin:
lbThreadState.Text="WaitSleepJoin";
break;
case ThreadState.Stopped:
lbThreadState.Text="Stopped";
break;
case ThreadState.Unstarted:
lbThreadState.Text="UnStarted";
break;
default:
lbThreadState.Text="Unknown";
break;
}
}
private void btOK_Click(object sender, System.EventArgs e)
{
MessageThread.Start();
}
private void btCancel_Click(object sender, System.EventArgs e)
{
RunThread=false;
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
RunThread=false;
MessageThread.Join();
}
If I click the Stop button (set RunThread to false) then close the dialog its fine, but If I close the dialog while the thread is runing it hangs...
I set the same variable to false in the Form1_Closing handler. I've tried using the IsBackground property, but this changes the ThreadState value to "12" apparently all the time.
I'm assuming that once I've hit the Closing Event handler that I'm at a point of no return or somthing with the worker thread, or something like that. Any suggestions ?
|
|
|
|
|
The hanging that you are seeing is caused by a deadlock. The Form.Closing event is calling Thread.Join . I'm sure you are well aware that this call blocks until the thread has terminated gracefully. You are blocking the UI thread until the worker thread completes. But, the worker thread may be (and likely is) attempting to call Control.Invoke which blocks until the UI thread has completed its execution of the specified delegate. So if the Form.Closing event blocked the UI thread and the worker thread is trying to marshal something onto it then you have yourself a nice little deadlock. Now, depending on the exact timing of things you may not see this deadlock everytime, but I'm willing to bet that you'll see it most of the time.
|
|
|
|
|
Yes, thats exactly it.
I've decided to solve the problem by setting the Worker thread as a BackGround Thread. Althought this seems to alter the ThreadState from the Enumed values to a numeric value, I decided to deal with it. It works fine now.
Thanks for the response and explanation though.
|
|
|
|
|
Consider the following code
byte[] message = new byte[40];
message[4] = (byte)'S';
message[5] = (byte)'S';
message[6] = (byte)'T';
message[7] = (byte)'A';
message[8] = (byte)'R';
message[9] = (byte)'T';
message[10] = (byte)'C';
message[11] = (byte)'S';
int retval = myStream1.Write(message);
This code is a C# code myStream1 is an object of a COM component, What would be equivalent code in VC++
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
replace
byte[] message = new byte[40]
with
byte message[40];
the rest should be the same.
Edit:
Probably should toss in Zeromemory(message,40) to clear the buffer.
i.e.:
byte message[40];
ZeroMemory(message,40);
message[4] = (byte)'S';
message[5] = (byte)'S';
message[6] = (byte)'T';
message[7] = (byte)'A';
message[8] = (byte)'R';
message[9] = (byte)'T';
message[10] = (byte)'C';
message[11] = (byte)'S';
|
|
|
|
|
A BYTE[40] . A byte is a byte, or 8 bits.
Note that how you're doing this now is not a very effective means. You should take a look at the Encoding class. Since you obvious are dealing with ASCII characters, use the ASCIIEncoding class to convert a string to a byte[] array. The way you're doing it works, but could be tedious to maintain.
If you're asking how you'd marshal this, you could return a byte[] from your managed code. The CCW (COM-Callable Wrapper) would use [retval] LPBYTE, more than likely. That's not automation compliant, however. For true OLE Automation, you might consider marshaling this as a SAFEARRAY (UnmanagedType.SafeArray).
Microsoft MVP, Visual C#
My Articles
|
|
|
|