|
See the class documentation for the HttpFileCollection class. You can use a simple HttpWebRequest to get the request stream and write one or more files using multipart-MIME to a Page (.aspx file). This is receieved as an HttpFileCollection which you can use to write each individual file to disk. This is a byte-for-byte copy.
If you're using Web Services or .NET Remoting, you can use DIME, for which more information can be found at http://msdn.microsoft.com/library/en-us/dnservice/html/service01152002.asp[^]. This is much faster than sending encoded byte[] arrays using SOAP.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
DIME is not an option given some of the client computers are win98.
I did some preliminary investigation into remoting and read somewhere about remoting being faster for small binary file transfer than SOAP but poor for large files ...
(btw i thought DIME used SOAP and not .net remoting ...?)
Thanks all for your speedy replies ... way faster than any of my newsgroup posts!
Rob
|
|
|
|
|
Neither DIME nor SOAP uses .NET Remoting - .NET Remoting (and Web Services) use DIME and/or SOAP (Remoting can also use other formatters).
While DIME is related to SOAP in that it's a solution to a problem, it's not really tied to it. DIME is simply prepending the actual bytes to the SOAP message and referring to it in the SOAP message body.
I'm not sure where you got that DIME doesn't work with Win98/ME. If the implementation requires it for some functionality, nothing's stopping you from implementing it yourself without such a requirement (which I've never seen, BTW). DIME is a specification. The WSE (Web Service Enhancements) supports it, but you can make your own implementation. There's plenty of conceptual and technical documentation on it, including the specification itself (don't remember where, but it'll be linked in various articles - probably on W3C[^]).
Also, if all you're doing is uploading files to a web server, you could always just stick with simple HTTP POST. It's easy. If you are needing this for a Web Services or .NET Remoting, you could always have the page that accepts the post return a cookie (not necessarily the HTTP kind - just a token that is associated with an operation) that you pass to the WS or Remoting object that identifies the group of files (perhaps stored in a file, database, or some session- or application-level cache if using the same AppDomain for the site and WS or Remoting host).
The simple point is that you want to avoid having to encode the byte[] array because its slow (typically, base64 encoding is used but this can be changed using variousing binding flags for the SoapFormatter ). If you use a BinaryFormatter as the format to be sent across the wire, you don't have to worry about this encoding problem (and its better for any size of file - or data, for that matter, but not always desirable because of interoperability with other platforms).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Sorry ... I meant the Web Services Enhancement for .NET from Microsoft does not run on a Win98 system (2k+ or XP only)
If you could point me to where I can find infor on DIME on a Win98 box that would be great!
Interoperability is not a problem given I control both ends of the system.
BTW I did implement uploading to a multipart/form-data page from my winform client but found it killed the server when the upload size exceeded 8mb .. asp.net caches the entire file to memory before writing to disk. Thats when i began to look into a chunking solution and then thought maybe theres even a better way to fire up these files to the server ...
Thanks Heath ... you've been most helpfull ... really appreciate it!
Rob
|
|
|
|
|
Just search google for DIME. As I said before, it's a specification. If the WSE is supported on Win98 (not really surprising, especially since 98 is about to become unsupported, as will ME in the near future...though not soon enough), then you need to implement it yourself. Just use the specifications on DIME to create an impementation. I already gave you one link with conceptual information in the content and links to more resources.
ASP.NET has a request limit, which is - like most things - configurable. The <httpRuntime> element in the machine.config file has a maxRequestLength attribute that specifies the maximum size (in kilobytes) of requests. This element (and hence its settings) can be configured at the machine level (machine.config), site (/Web.config), application (Web.config), or sub-directory (same) level.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I know about the config file settings ... but when you punch it up to, say, 50mb, asp.net chokes cause it caches the entire upload to memory before writing to disk ... thats why i began exploring a chunking solution.
In any case, thanks again Heath ... you've been most helpfull!
Rob
|
|
|
|
|
Then don't use a Page derivative, use a simple IHttpHandler implementation, or the built-in .ashx support (like .aspx and .ascx handlers, only to implement a simple IHttpHandler ). Write to disk as the stream is read on the server (and don't forget good clean-up code, of course, if it fails).
Chunking is still a good idea, but there's always different solutions.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How about FTP? Probably best to get a third party component, but at least it's a well understood and well supported solution.
|
|
|
|
|
Hi Guys,
only a short question. Is there a way to scan a Text in a Textbox and Compare it with a text in a file, or even parts of a other textbox text? Would be great if anybody has a solution in source or hints.
Thanks all...
Eolus
If you want realize your dreams, you should not sleep!
|
|
|
|
|
if (textBox1.Text == textBox2.Text)
MessageBox.Show("They match!"); If you want to compare it to a file, use a TextReader to read each line and use line.IndexOf(textBox1.Text); to determine if the line contains the text in textBox1 .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath,
sorry but i must ask you again, the first time i wrote it not clear enough.
I must compare text in a Textbox with a textfile and if there is a match, it should copy the code lying behind.
The first thing is something like that: <FHGO> (but it's not HTML-tags),
the second thing are normal letters: A B C and so on
Hope it's little clearer to you
Eolus
Sorry for my bad english...
If you want realize your dreams, you shouldn't sleep!
|
|
|
|
|
From what I can see, I think Heath's suggestions that you read the file line by line using the TextReader.ReadLine method and then calling the IndexOf method on the returned string is the way to go.
It will get you the location of the begining of the text in your text box on the current line of the file. Then you just need to break up the rest of the string to get what you need.
I'd need to know more about the file structure and what you'll be searching for to make a more concrete suggestion.
Bill
|
|
|
|
|
That's what I was going to suggest. Thanks!
Regarding this last statement - and directed to the original poster - if your text spans multiple lines, then you must take that into account either by removing line breaks when reading strings into your application from the file, or use a Regex class/statement that spans multiple lines (regular expressions - very powerful; get to know them). Regex's are an advanced string parsing algorithm.
See the Regex class in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Okay i give you an example:
Text in a Textbox:
<FHGO><BIG>Hello World!
Textfile:
begin raw_codes
name <FHGO>
8561 4107 609 440 601 439
600 438 604 439 600 437
600 440 597 436 602 435
600 4120 617 435 603 439
598 1478 613 1478 608 1478
615 435 600 436 603 436
600
name <BIG>
8562 4107 608 443 594 443
600 441 602 444 593 443
596 443 601 445 594 443
601 4120 609 1480 608 1478
611 1479 609 1479 609 1478
608 442 598 441 600 443
598
name A
8528 4136 579 448 579 450
580 449 580 448 578 450
579 449 579 448 578 447
579 4149 579 447 581 1503
581 448 578 1505 580 448
580 449 578 450 579 450
578
...
So i need to scan the textbox und compare it with the textfile and get the code behind back. I think a Problem would be probably that "A" is also in Name. I hope there is a solution to solve my Problems
Eolus
If you want realize your dreams, you shouldn't sleep!
|
|
|
|
|
Yeah, and we gave it to you. Scan lines like we told you until you find a string match. Then keep reading lines in using TextReader.ReadLine until you encounter (apparently) an empty line. This is really a simple problem.
If you think your TextBox content is too ambiquous, then use "name " + textBox1.Text . Keep reading lines from the text file until you find it, then follow what I said above to read the rest of the lines until you encounter a blank line.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
So the textbox can contain an arbitrary number of <name>'s? For example: one time I could enter '<FHGO>SomeText', next time '<FGHO><A>SomeOtherText', third try '<FGHO><A><BIG>SomeThingElse' and you want to get 1, 2 or 3 (or N) code blocks?
If so, you need to two two things:
1) parse up your textbox string into individual <name>'s. Here the Regex class Heath refered to is an IDEAL tool.
2) for each <name> you get, search the file. You'll want to do write a method something like:
<code>
private string strFindCode(strName){
TextReader trCodeFile;
//open the text file here....
bool bFoundIt=false;
string strCurrentLine;
string strCodeBlock="";
while(trCodeFile.Peek()>-1 && !bFoundIt){
strCurrentLine = trCodeFile.ReadLine();
if (strCurrentLine.IndexOf(strName)>-1){
bFoundIt=true;
strCurrentLine = trCodeFile.ReadLine();
while (strCurrentLine != ""){
strCodeBlock+=strCurrentLine +"\n";
strCurrentLine = trCodeFile.ReadLine();
}
}
}
trCodeFile.Close();
if (bFoundIt){
return(strCodeBlock);
}else{
return("Name Not Found");
}
</code>
I have not compiled, much less run, this code. So I make no promises...but hopefully it points you in the right direction algorithmicly.
Bill
ps: please don't everyone jump on me for not using the StringBuilder...
|
|
|
|
|
Hi all,
I have a TextBox control that only takes in numbers, the final *bug* i have to solve is when the user right clicks on the control and the popup menu appears with undo, cut, copy, paste, etc on it.
What event can i use to deal with when they select paste?
I need to solve this to stop the user pasting text into the control that isnt numbers.
This isnt a context menu i have attached to the control so the ContextMenuChanged event doesnt fire, which is the event i thought i should be using.
Anyone got any ideas where i'm going wrong?
Thanks
|
|
|
|
|
If you've extended TextBox with your own, override OnValidating ; otherwise, handle the Validating event. This allows you to cancel the operation if anything but numbers are pasted and will restore the previous text (since Validating fires before the Text is set). See the documentation for the Validating event to see an order of events. The only problem with this method is that the control must loose focus first.
If that's not sufficient, then extend TextBox (if you haven't already) and override WndProc . Handle the WM_PASTE notification message (0x0302) and throw it out (i.e., don't call base.WndProc ) if the Clipboard text doesn't contain numbers. You could handle this a few other ways, but hopefully this will get you started.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks!!!
The override of WndProc is just what i needed, i'll get on with it that way.
I really must remember WndProc when i get stuck.
|
|
|
|
|
Hi,
When we generally click the cross on the caption bar, our application (or our Form) will close and it is automatic action.
I'd like close my application when I'll click the cross on the caption bar and I'll confirm this action. When I'll not confirm it, application shouldn't be closing.
I try use the Closing event, but I don't know how interrupt closing app.
Regards
Kamil
|
|
|
|
|
Hi,
If you override the forms "Closing" event then have some code like below this should help you out.
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (MessageBox.Show("Do you wish to close?",
"AppName",
MessageBoxButtons.YesNo) == DialogResult.No)
e.Cancel = true;
}
By changing e.Cancel to true the event will not complete and your form will not close.
Hope this helps
Simon Wren
simon.wren@nesltd.co.uk
Senior Software Architect
National Energy Services Ltd
Visit Us: www.nesltd.co.uk or: www.nher.co.uk
|
|
|
|
|
Except this isn't overriding, this is handling the Closing event. Since it's typical to extend the Form class with your own (VS.NET does this for new Windows Forms application proejcts), you override the event handler, OnClosing , which is better (faster, more control) than handling the event in a derived class:
protected override void OnClosing(CancelEventArgs e)
{
DialogResult result = MessageBox.Show("Do you want to close?", Text,
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result != DialogResult.Yes)
e.Cancel = true;
base.OnClosing(e);
} That's overriding. In this case, you'll still want to call the base class's handler, but in some cases (like when you want to throw messages out in WndProc ), you don't want to call the base class's method.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks, i did get my use of the word override wrong in my first response
Out of interest you mention that using OnClosing is faster, why is it?
|
|
|
|
|
When you handle an event, you actually add a reference - a managed pointer - to a list of handlers. That reference must be added to a list - which may have to be resized, which takes time. Even adding the referenec to that list is an O(n) operation, where n is the number of list items currently in the list.
When the event is fired, the list of references to delegates is enumerated and each delegate is invoked. The EventArgs derivative may need to be "queried" in between each invocation to keep track of whether or not something needs cancelled (in this case).
That's all quite a bit more than simply a virtual call (callvirt IL instruction), which is polymorphic.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Look in the EventArgs object.
You have to do something like
e.Cancel = true;
However I do not remember the EXACT property name so search for it.
______________________________
The Tao gave birth to machine language. Machine language gave birth to the assembler.
The assembler gave birth to the compiler. Now there are ten thousand languages.
Each language has its purpose, however humble. Each language expresses the Yin and Yang of software. Each language has its place within the Tao.
But do not program in COBOL if you can avoid it.
|
|
|
|