Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi All,

Problem: I have a multiple files. These files displayed by using listbox. When select any one of the file from listbox it should be copied into another file and I don't want the full content of file I want only some part of a file copied into another file. I think this can be done through the memory stream.

I wrote this much of code
string sourceFile = listBox1.SelectedItem.ToString();
            
 string destinationFile = @"D:\Sowjanya\Directx files\Hero.X";
            try
            {
                //causes exception if already exists.
                File.Delete(destinationFile);
                string str1="animationset";
                if(sourceFile.Contains(str1))
                File.Copy(sourceFile, destinationFile);
                MessageBox.Show("Copy completed.");
            }

            catch (Exception e1)
            {
                Console.WriteLine(e1.Message);
            }
            Console.Read();

It was copied whole content of file ... but I want some part text only
i.e if the file contains the animationset method that whole method must be copied into antoher file. That selected file is must be having an animationset method like this
animatinset
{
.......
}

This is what I want

Please help me.
Posted
Updated 2-Feb-10 10:18am
v2

1 solution

sowjanyagadela wrote:
It was copied whole content of file.... but i want some part text only


Well, you DID call File.Copy. Yo don't need a memory stream. You need File.ReadAlllines or File.ReadAllBytes to read the whole file in memory, then you need to parse the file to find the bits you want to copy, then you can use a similar overload to write the new file fragment.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900