|
Hi Johan, I think without using Win32 to read/write the files at a lower level, what you've come up with is the best that .net can offer. The method below works in exactly the same way with a couple of minor changes for memory efficiency & some personal preferences - there's no need to create a new byte[] on each loop; just use the same buffer that you define at the top. I usually use a buffer size of 4KB as a balance between memory usage & file access operations. There's no need to calculate the buffer size to ensure you don't read past the end of the file - .Read returns the number of bytes actually read, even if you asked for more than is available. Finally, a personal preference, I like to use using() blocks with the FileStream just to guarantee the file is closed (the Dispose method on Stream is actually hidden, but it is there & calls close).
Hope this helps, Rob
private void JoinFiles(string[] files, string outputFileName)
{
byte[] buffer = new byte[0x1000];
using (FileStream fsSave = new FileStream(outputFileName, FileMode.CreateNew, FileAccess.Write, FileShare.None))
{
foreach (string file in files)
{
using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
while (true)
{
int count = fs.Read(buffer, 0, buffer.Length);
if (count <= 0) break;
fsSave.Write(buffer, 0, count);
}
}
}
}
}
"An eye for an eye only ends up making the whole world blind"
|
|
|
|
|
great. less code, a single buffer, my 5.
|
|
|
|
|
Thanks a lot for you answer, it's a much better looking code and it's easier to read.
I just love getting feedback and watching how others write their code, there's a lot you can learn from that.
So thank you again...
|
|
|
|
|
I want as the installer runs, it pauses and asks for the serial key to continue installing. Just as Windows XP or Office does. I understand that this might not be related to C Sharp coding exactly but i did my software with C Sharp! I am using Visual Studio 2005. How can one configure the installer to do that?
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
You can look at this [^]article at MSDN for validating the serial key.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hi,
I've created a Groupbox, there is a textbox in subset of it.
I've changed Groupbox's RightToLeft property to Yes, But I wanna change it for textbox to NO.
I couldn't do it , because textbox is in subset of Groupbox.
Could you please guide me , how I can change it ?
Thanks.
|
|
|
|
|
Your question is not exactly clear, but I am taking it to mean that you have created a Control which inherits from GroupBox and this control contains a TextBox .
You can set the property in design view of your control but if you want to be able to do it once your control is placed on a Form (for example), you need to surface any properties of child controls in your control. Something like this:
[Category("Appearance")]
public Color CountryTextBoxBackColor
{
get
{
return this.countryTextBox.BackColor;
}
set
{
this.countryTextBox.BackColor = value;
}
}
I have used BackColor in this example because I couldn't remember the Type for RightToLeft but the principle is exactly the same. You will need to do the same for any properties of child controls that you need to be available at design time.
The code above should be part of the code for your control, in case you have not worked that out.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
I will give an exmaple. We have a list box and a text box. On click of a button the text box will get enabled and the text enterd in the text box will be displayed in the label on another button click. This data is not saved. Now when i close the application and run again the labels are empty. How to store the entered data and display it in label.
Thanks,
Santa
|
|
|
|
|
There are quite a few ways you can do this. What have you learnt on your course so far, that might be applicable? What have you tried?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Please tell me how to do it. The example which i have given above in the thread is what i have tried. But when we close the applicationa dn run it again i do not get the same names in the labels.
|
|
|
|
|
I'm not going to give you the solution to your homework!
You will have to think about it a bit, but I'll give you a few clues:
System.IO.File is one way.
System.Configuration is another.
There are (probably) a dozen or so ways this could be done. Have a look at Google, and try something. When you have a specific problem (other than "I can't do my homework") post some details of where you are stuck.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Information displayed in Windows (forms) is placed there by the application that owns the forms. Information entered by the user must be saved somewhere by the application if it is needed again. You must decide how and where to save it so that it is available next time you run the appication.
|
|
|
|
|
I am working on Web application. And i do not want to store the data in DB and bring it back from ther. IS there any other possible ways to do it.
TIA.
Thanks,
Santa.
|
|
|
|
|
Storing it in a DataBase may be the best option; it all depends on how your application works. As I said before you must decide where is the best place to store this information. See earlier suggestions, also consider a flat file, the Registry etc.
|
|
|
|
|
For a web app, the user may run it from any computer so storing stuff locally is unlikely to be what you want, a DB on the server is a good idea.
|
|
|
|
|
how execute exe files in C#.net?
|
|
|
|
|
Use using System.Diagnostics NameSpace.
Then use Process Class to Execute an Exe.
eg:
Process.Start("IExplore.exe")
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
If you need to pass some arguments to the exe file, here is an example
Process p = new Process();
ProcessStartInfo ps = new ProcessStartInfo();
p.StartInfo = ps;
ps.FileName = "file.exe";
ps.Arguments = "Some commandline arguments";
p.Start();
|
|
|
|
|
|
It seems you have joined code project Today . So welcome to CodeProject.
Mishra Aditi wrote: hi how r u???????
Please Don't SPAM.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
This forum is for C# programming questions, not illiteracy.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
None the better for having read your spam.
|
|
|
|
|
Hi,
i am developing text editor (windows application) by using c#.net.
in my text editor i am providing a rich text box to enter text.
it has multiple rich text boxes to make it act like multiple pages.
after entering text into some number of rich text boxes user can go for print.
printed pages should be in WYSIWYG format.
i am able to send all the text from all the pages to the printer. but my problem is i am unable to achieve WYSIWYG. that is
say for example in the first rich text box of my application have 30 lines then the printer is printing less than 30 lines per a page.
so finally i am trying to develop one application which is almost similar to MS WORD.
so please explain me how can achieve this ??
if you have solution please email me at
anilveeraghattapu@gmail.com
Thanks
Anil Veeraghattapu.
|
|
|
|
|
Firstly, do not post your email, unless you like spam.
Secondly, have you tried doing this?[^]
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|