|
You can use FileInfo Class.
FileInfo fi = new FileInfo(strFileName);
long fileSize = fi.Length;
Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net
|
|
|
|
|
I have a service that collects information from a UDP port. I would like to have a program when a user is connect that display information when the service is collecting data.
So, how can a program can be notify by a service ?
(PS.English is not my first language...)
|
|
|
|
|
There are various ways to approach this.
For example you could establish a simple TCP connection, exchange UDP packets or use Remoting. It's up to you.
www.troschuetz.de
|
|
|
|
|
Hi all,
I would like to ask a question on software design.
In C#, we can directly bind the view control (e.g. text box) with
the data get from database by the dataset object. By doing so,
it would completely eliminate the middle object layer, i.e. the relational
data is directly put onto the UI. Is this a good approach ?
For me, I will add a middle object layer in between the database layer
and the view control, so first instantiate the object by the data from the
database, then bind the object to the view control. Is this method a good practice ? If yes, why there exist the dataset class in C# ?
Thanks
|
|
|
|
|
I’m fairly new at this so these are just my thoughts don’t take them as the gospel truth.
To directly bind something like a textbox to a Sql db field would mean that the Db connection would have to permanently open. I don’t think that is usually a good idea. However an idea to “loosely” bind it might me to on creation of the form open a connection to the Db and on the onChange event from the textbox (or a submit button) throw an insert string to the db using the DataSet object. Then retier the DataSet and get a new one.
It seems kinda sloppy though.
I’d be curious to here what you think.
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
Hi, does anyone know how i can launch a form: new FormName().Show();
without giving the form focus?
EDIT: Better yet, is there anyway to make it so that the form cant recieve focus? I get a readonly error when I try to do this.CanFocus = false;
Thanks
- Alex
|
|
|
|
|
Does anyone know how to do this?
Can it be done using [DllImport("user32")] ?
|
|
|
|
|
CanFocus is readOnly property, You can not assign any value to it. This is the main cause of the error.
You should do as below:
you can write the below code in Form1(say)
Form2 f2 = new Form2();
f2.Show();
this.Focus();
|
|
|
|
|
Im actually not trying to shift focus to the main form, im trying to make it so that the user doesnt lose focus from the window that he is currently looking at.
How can i do that?
|
|
|
|
|
Above code results the same what you are looking for.
|
|
|
|
|
Wait so if the user is working in microsoft word for example, and this form pops up (it is used to notify the user), it wont take the focus away form microsoft word?
Because thats what im tring to achieve.
thx
|
|
|
|
|
I am pasting image in a richTextBox using clipboard.
It works fine. But I want to restore the previous clipped data.
Any clue, How to go for it? The code I am using for trial is, as below
private void PasteImg(RichTextBox richTextBox1, string imageFileName)
{
System.Windows.Forms.DataObject prevDat = new DataObject();
prevDat.SetData(Clipboard.GetDataObject());
#region Pasting the image
if("" == imageFileName) imageFileName = @"c:\JayShared\music.bmp";
Bitmap myBitmap = new Bitmap(file);
Clipboard.SetDataObject(myBitmap, false);
DataFormats.Format myFormat = DataFormats.GetFormat (DataFormats.Bitmap);
if(richTextBox1.CanPaste(myFormat))
{
richTextBox1.Paste();
}
#endregion Pasting the image
Clipboard.SetDataObject(prevDat, true);
}
|
|
|
|
|
The major problem is that the managed IDataObject and OLE clipboard functions (which support drag-n-drop) don't support nearly as much as the OLE IDataObject and related functionality. The best thing you can do is just store save the IDataObject (don't store it in a DataObject ; you could loose a lot of data) and restore it later:
IDataObject oldData = Clipboard.GetDataObject();
Clipboard.SetDataObject(); You still run the risk of losing some data for certain applications that may sink events with the OLE implementation of the native IDataObject interface. Even the Office clipboard ring, for example, can't save everything (typically when the media type is TYMED_ISTREAM or TYMED_ISTORAGE because the provider may want to provided data to stream that may no longer be available depending on the connection to an advice sink).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Dear Heath,
Thanks a lot for your reply.
I modified the function as below and tested with copying text on Clipboard before entering into the function and after execution of the function. But the test result failed for 1.TextPad 2.Notepad 3. MS Word.
I have modified the code as below.
IDataObject oldData = Clipboard.GetDataObject();
System.Windows.Forms.DataObject prevDat = new DataObject();
prevDat.SetData(oldData);
Clipboard.SetDataObject(prevDat,true);
Can anything be done further?
Or Should I modify the pasting of image in richTextBox functionality, which does not use Clipboard.
Regards,
Jay
|
|
|
|
|
I said do not store the old data in a managed DataObject . You keep it as it - as an interface reference. That has the greatest change of preserving the data that is there. Once again:
IDataObject oldData = Clipboard.GetDataObject();
Clipboard.SetDataObject(oldData);
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
It results System.Runtime.InteropServices.ExternalException : The requested clipboard operation failed. Error.
Regards,
Jay.
|
|
|
|
|
On what line? What does your code look like? Please be more specific. I can't help you if you just give me tidbits of information. Why do you think doctors want you to come in in order to diagnose problems, besides charging you money (which we don't do here, so that's even more incentive to be verbose).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am really sorry for not elaborating the scenario.
Below are the details.
Steps resulting error
1. I. Open TextPad / MS Word, II. write text III. Copy the content in the clipboard
2. I. Run the C# Application II. Call the method
3.Causes Runtime eroor at Clipboard.SetDataObject(oldData) line ;
4. Error Details :
System.Runtime.InteropServices.ExternalException : The requested clipboard operation failed.
Code :
private void PasteImg(RichTextBox richTextBox1, string imageFileName)
{
IDataObject oldData = Clipboard.GetDataObject();
#region Pasting the image
if("" == imageFileName) imageFileName = @"c:\JayShared\music.bmp";
Bitmap myBitmap = new Bitmap(imageFileName);
Clipboard.SetDataObject(myBitmap, false);
DataFormats.Format myFormat = DataFormats.GetFormat (DataFormats.Bitmap);
if(richTextBox1.CanPaste(myFormat))
{
richTextBox1.Paste();
}
#endregion Pasting the image
Clipboard.SetDataObject(oldData);
}
|
|
|
|
|
Jay Shankar wrote:
It works fine. But I want to restore the previous clipped data.
Well, I'm not sure if that's your problem but when I execute your code I get a COMException (Error HRESULT E_FAIL has been returned from a call to a COM component) after Clipboard.SetDataObject() has been called but that might be due to the .NET Framework 2.0 (no, I don't have a version 1.x installed ). Anyway. It should work fine when you replace the first two line with:
IDataObject prevDat = Clipboard.GetDataObject();
This is also how it's done in the code sample in the Visual Studio Documentation (see Clipboard.GetDataObject Method[^]). Please let me know if this hint solves your problem.
Best regards
Dennis
|
|
|
|
|
Dear Dennis,
Thanks a lot for your reply. I modified the function as par suggestion by you and Mr. Heath. But could not achieve the goal. Still trying....
Regards,
Jay
|
|
|
|
|
I'm looking to drive a class definition off of a configuration file and make the properties be definied through code using the PropertyBuilder class in Reflection. The one thing we can't figure out is if we can make the dynamic properties available in intellisense or even in code. Our goal is to make the dynamic class appear as a static coded class, so all the intellisense features are available. I assumed shadowing GetType() would do it and force VS.NET to use the correct type def, but it doesn't appear to work.
Does anyone have any thoughts on how to make it work. Is there a method we can override that VS.NET uses to introspect the object?
|
|
|
|
|
You will need to to reference the generated assembly in the project. That should allow intellisense to pick up the classes. If the code is generated and incorparated into the build, then just adding the generated files should be enough. Look how xsd -> cs is done.
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
Take a look at the CodeDomSerializer class, which you can use to persist a file that IntelliSense can parse. This is how code is generated from XSD files, Windows Forms controls and forms, etc.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hey
I have been looking into som article here on Codeproject about remoting.
There is some thing i dont understand realy.
I have tryed to make a object(from dll file) active(creat) by using remoting(SingleCall).
The client simes like it gets the object but its empty.(I know that the client is working)
How do i fill the object with info? I have tryed do creat the object on the server and add the info to it, but when the client request a remot obj it takes a new one.
I have thougt of writing the info in the dll file, but then i dont realy need the server to transfer it when all the info is already in the dll file on at the client. I could let the dll file open a file on the server an read info there but this dont simes right?
How do i let the server add information to the object that the client is geting info from?
Server Code:
hc = new HttpChannel(10034);
ChannelServices.RegisterChannel(hc); RemotingConfiguration.RegisterWellKnownServiceType(typeof(QuoteService.Quotes),"QuoteServer",WellKnownObjectMode.SingleCall);
Remote dll(QuoteService.Quotes):
Arraylist that stors objects of an other class(QuoteService.Quote) that also is : MarshalByRefObject
Client Code:
hc = new HttpChannel(); ChannelServices.RegisterChannel(hc);
QuoteService.Quotes quote;
Random ranobj = new Random();
quote = (QuoteService.Quotes)Activator.GetObject(typeof(QuoteService.Quotes),"http://localhost:10034/QuoteServer");
This problem is probely silly!
//Jimmy
|
|
|
|
|
NoOne that can explain how to creat object on server and give it serten values and then to let the client read the information that the server have stored in this object(dll file)
//Jimmy
|
|
|
|