|
Hi
i want to transfer files and data throw modem .we have 2 pc and 1 tel line and want to send and recieve by this line so how can do it?
Regards' amir jalaly
|
|
|
|
|
It really doesn't matter what the connection device is. So long as you're connected, you can use a myriad of classes to transfer files. You could create a simple TCP socket connection using the TcpClient class, for example. If an accessible share exists on one or the other machine (or both), then you can simply use File.Copy to copy files, although this typically won't work because of default security (and anonymous write permissions are too risky).
You could also go all-out and create a .NET Remoting client/server between the two, transfering files as byte[] arrays, or better yet use DIME (part of the WSE 2.0, which you can download from MSDN[^]. DIME gets around serialization, which is a big performance boost.
So, just forget that a modem is connecting to the two clients and use whatever class(es) you'd like. So long as TCP/IP is the protocol connecting the clients, your options are many; otherwise, you'll need to create a Socket connection with the correct AddressFamily .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I have a datagrid, which represents a datatable fetched out of my DB. If I click on the column in the toprow in my grid the grid gets sorted. Perfect: So far so good.
Now it seems that (after sorting) the datatable and the datagrid do not correspond anymore .
Can anyone tell me how I can manage to sort my datatable together with my datagrid? (or equally good just to get the correct row (primary key or something??)) I don't want a roundtrip to my database.
TNX A LOT!!
I forgot: it's about winforms no webforms
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
Tried a DataView?
Create a DataView from the DataTable, set the Sort property on the DataView, set the DataGrid's DataSourse to the DataView.
Hope this helps
Bill
|
|
|
|
|
Hi:
I am using WilsonDotNet (www.wilsondotnet.com) ORMapper to map my Business Objects to C# classes. My Business class, because of its object inheritance hiearchy contains more properties than I want to display in my DataGrids. The plain vanilla way of binding a IList object to a DataGrid is to set the DataGrid.DataSource property to the object. But since this displays all kinds of info that I want to hide I was exploring using the DataGridTableStyle object and DataGridColumnStyle object. Because of my neophyte status this exploration contains the distinct possibility of my banging my head against the .Net wall for a good period of time, so to avoid this mental anguish I was wondering if anyone had done this and whether it was possible.
Any hints would be deeply apreciated.
Mike
|
|
|
|
|
You can use table styles and column styles for objects besides the DataTable . The column style's MappingName is the name of the property, plain and simple. The information you need to read is the documentation for the DataGridTableStyle.MappingName property in the .NET Framework SDK. This is where it gets down to details about mapping to objects.
For a table, it's obviously the table name (whether you set a DataTable to the DataGrid.DataSource property, or set that property to a DataSet and specify the table name in the DataGrid.DataMember , which is actually a better way of doing it for many different reasons). For an array, use the type name plus the array indexer operator (ex: MyClass[] ). For another implementation of the IList interface besides those, just specify the type (ex: ArrayList ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath:
Thank you for your help. I found the help associated with the DataGridTableStyle.MappingName and created a small form based on the NorthWind Category to Product relationship. When I bind the DataGrid using:
this.productsGrid.DataSource = this.category.Products;
I can see all the data.
When I use this code duplicated from the Machine[] example in the help file the grid shows nothing
DataGridTableStyle productsTable = new DataGridTableStyle();
productsTable.MappingName= "Products";
DataGridTextBoxColumn nameColumn = new DataGridTextBoxColumn();
nameColumn.MappingName= "Name";
nameColumn.HeaderText = "Name";
productsTable.GridColumnStyles.Add(nameColumn);
productsGrid.TableStyles.Clear();
productsGrid.TableStyles.Add(productsTable);
My definition for product looks like:
public class Category : Wilson.ORMapper.IObjectHelper
{
private int id;
private string name;
private string description;
private IList products;
public int Id {
get { return this.id; }
}
public string Name {
get { return this.name; }
set { this.name = value; }
}
public string Description {
get { return this.description; }
set { this.description = value; }
}
public IList Products {
get { return this.products; }
}
}
|
|
|
|
|
As I mentioned to someone in an earlier post today, you don't need to clear the table styles. Note that plurality: DataGrid.TableStyles . So long as a unique MappingName exists for all the DataGridTableStyle s you have for the DataGrid , you can keep them all in the collection. This is especially nice when you want to bind different data sources to the same DataGrid .
Also, if you cleared the DataGrid.TableStyles and added a new DataGridTableStyle after setting the DataSource property, nothing will show up: table styles are used when binding the DataGrid , but from what I can tell in the IL for the related classes and methods is that changing the table styles does not re-bind the data source (which is actually a good idea in case you wanted to modify table styles while binding a large dataset).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I saw that posting. Even if I remove the clear nothing shows up. Could you clarify this statement:
When you're applying a style, you must re-bind the data source. The data source is "stylized" during binding.
1. How do you apply a style from the collection?
2. By rebind do you mean I need to issue a
productsGrid.DataSource = category.Products; or SetDataBindings after applying the style.
Which seems to just redisplay the entire products collection.
|
|
|
|
|
To re-bind, you must first set DataSource to null and then set it to your data source again.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
First, I am not a C# programmer (although I am trying to learn). I have an intern doing the coding for me on this current project, and he is still trying to put together what they teach in school with the real world.
OK, so here's the problem and question...
A form contains a datagrid (2 columns) and some buttons. We want to prevent a record with either of the fields being null from being written to the database (using MSSql). The table in question is set up with "Allow Nulls" as false. This means that if the user clicks "OK" the message "Column 'Div_Code' does not allow nulls......"
This is fine for me, I know what that means. My users don't. They know the field by the name "Division", and they have no idea what null means.
I would like to do either of the following (and I guess there could be a great deal of discussion about which of the solutions is the most elequent):
1) Either check when leaving the field that it is not null. We tried the columnChanging event, but this doesn't work because the field starts as null, ends as null, and only seems to fire when the value changes; or
2) Intercept the message from the database and substitute our own. I tried using a Try block, but although I traced the execution, I could not see where the message came back.
Anyone have a solution (and if there is a 3rd, 4th or 5th approach, that's good also).
Thanks much...
Alan B
|
|
|
|
|
Try handling the DataGrid.CurrentCellChanged event, which is actually independent of the data source. That way the "bug" (as it seems) where null values in a column doesn't fire the ColumnChanging event doesn't really apply. Another option is to bind to a DataView where AllowDBNull is false . The exception message should be fired immediately when the field looses focus so it would take a pretty stupid user (and, yes, I know they exist in mass quantities) to not realize that the value they just entered (or rather, the lack of a value) is not valid so they need to change it.
You can bind a DataGrid to a DataView just as you can any IList or IListSource implementation.
You're not catching an exception because an exception is not thrown by the DataGrid . If anything, it's handling the exception (or just using good error checking) and just displaying a message on its own. Simply throwing an exception would not result in such a message box (at least, not looking like that).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have an app that is an MDI Parent. You can open up multiple child windows and you even have an option to save them (save their position, size, etc...). When I restore them I have a problem because the Z-Order position of the child windows don't get saved. If you have windows that overlap in a particular way the order of the overlap does not get persisted. Anyone know how to do that ?
|
|
|
|
|
Serialize the order yourself. I'm not sure if the Form.MdiChildren is in any order (and the docs do not say), but assuming that they are (and you can always test it) you can do this. Also, is the Z-order when the MDI child forms are deserialized in reverse of what they should be? If so, then it's because they are saved in the same order in which they are read, so you actually need to reverse such a collection of elements (or however you're saving this information) so they are put back in the right order (since newly created MDI child windows will be on top by default).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
I was doing an exercise in Kalani's 70-316 book (Exercise 3.1, page 270) concerning exceptions.
The exercise calls for creating a rich text box and loading rtf's into it. However, there is exception handling code in place to handle times when you try to open or save to a file that is already open. The thing is, it doesnt seem an exception is raised at all.
The code has the load file call in a try block and is set to catch IOExceptions and then display a messagebox, indicating that the file is being used by another process. But, when I run the program I can open the file as many times as I want with many different apps. It never complains about the file being used by another program.
Is it not an exception then to use RichTextBox.LoadFile on an already opened file? (I can also save if the file is open by another app)
Thanx for the help,
-Flack
|
|
|
|
|
The RichTextBox doesn't keep the file open so long as you can see it in the editor. The RTB will open the file, read it, then close it. Same thing when the file is saved. If you have two RTB's loading the file AT THE SAME TIME or if the file is locked open by another application (Notepad, Word, ... will NOT do this!), then the exception will be generated.
You can write a small test app that does this. Just create a small app that will open the file on one button click (you don't have to read it, just Open it), and closes it with another button.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
am working on a project which uses pre-compiled executables (for example, makefile.exe) and I want to know if there is a way I can call this program from a C# command, something like:
Application.External.Run(string path, string args)
Application.External.Run("makefile.exe", "/build \"newfile.exe\"");
It doesn't have to be exactly like this; any way is fine. I just want to find SOME way to call another executable with some command line arguments.
Help would be greatly appreciated,
~ZeldaFreak
|
|
|
|
|
Check out the Process class. (Docs on MSDN[^])
Process.Start("C:\\mypath\myexe.exe", "myargs /moreargs");
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Can any one of you let me know, how can I replace a pattern in an html file using C#?
I have the contents of the html file stored in a string. I just need to replace some of the elements which have a similar pattern?
ex: I have a field {Token = LoanNumber} in the html file.
I just need to replace Loan Number with some text by finding the pattern "{Token=}".
Any suggestions are welcome.
Thanks.
|
|
|
|
|
You can use Regular Expressions to do this. Given the example string you posted, your pattern matching string might look something like this:
String token = "Token";
String pattern = @"\{" + token + @"=[\w]*\}";
This will find "{token=somevalue} ".
Your replacement string will look something like this:
String newValue = @"4321";
String replacement = @"{" + token + @"=" + newvalue + @"}";
So now, in a RegEx Replace operation, the result will be:
I have a field {SomeToken=54342643} in the HTML file.
will become
I have a field {SomeToken=4321} in the HTML file.
Create the RegEx object and execute the replacement with something like this:
RegEx regEx = New RegEx( strPattern, RegexOptions.IgnoreCase );
String resultHTML = regEx.Replace( strSourceHTML, strReplacementString );
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Im writing a PocketPC app. The application works fine with the emulator but when i deploy it to my xda2 when trying to create the dataset i get the following error
An unhandled exception of type 'System.TypeLoadException' occurred in System.Windows.Forms.dll<br />
<br />
Additional information: Could not load type System.Data.DataSet from assembly System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=B77A5C561934E089.
Anyone have a suggestion of whats wrong and how to fix it?
|
|
|
|
|
I could be wrong here, but it sounds like you developed your app on one version of the .NET Framework and the Pocket PC is running the other? (1.0 and 1.1)...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I believe the problem could be because I just installed the Whidbey release. So maybe VS.NET2003 has compiled my app against CF 2.0 rather than 1.0. How can i change what version of the framework an application uses?
|
|
|
|
|
Well, since your using the beta version, I don't know if this is going to work. Go to your Project Properties and find the Supported Runtimes option. The problem is, I don't know if your going to find this option in a CF Project! If not, you'll have to install the Whidbey Framework on your Pocket PC.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I decided to uninstall the CF on the xda and then reinstall it. But before installing it i decided to give the app a go, and strangely it works fine now, although i removed the cf from the settings->remove programs. Oh well it works now!
|
|
|
|