Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
I know how to copy it but i want to copy it in a sequence. Plz help.
Posted
Comments
[no name] 21-Jun-14 9:16am    
What have you tried to do for yourself? What was the problem with what you tried?
OriginalGriff 21-Jun-14 9:18am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Pankaj Mahor 21-Jun-14 9:52am    
I want to copy embedded text file to another location like c: drive or any location on a computer system in a number sequence like myfile1.txt, myfile2.txt...

here is the code

C#
private void button1_Click(object sender, EventArgs e)
      {
          try
          {
              var resourceName = "WindowsFormsApplication3.TextFile1.txt";
              WriteResourceToFile(resourceName, "C:\\1.txt");
          }
          catch
          {
              MessageBox.Show("Error accessing resources");
          }
      }
      public void WriteResourceToFile(string resourceName, string fileName)
      {
          using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
          {
              SplitFile(resource, fileName);
          }
      }
      public void SplitFile(Stream source, string sourceFileName)
      {
          string destFileLocation = @"C:\";
          int index = 0;
          long maxFileSize = 52428800;
          byte[] buffer = new byte[65536];
          while (source.Position < source.Length)
          {
              index++;
              // Create a new sub File, and read into t
              string newFileName = Path.Combine(destFileLocation, Path.GetFileNameWithoutExtension(sourceFileName));
              newFileName += index.ToString() + Path.GetExtension(sourceFileName);
              using (Stream destination = File.OpenWrite(newFileName))
              {
                  while (destination.Position < maxFileSize)
                  {
                      // Work out how many bytes to read
                      int bytes = source.Read(buffer, 0, (int)Math.Min(maxFileSize, buffer.Length));
                      destination.Write(buffer, 0, bytes);
                      // Are we at the end of the file?
                      if (bytes < Math.Min(maxFileSize, buffer.Length))
                      {
                          break;
                      }
                  }
              }
          }
      }


resources:
to split it to some files are[^]
 
Share this answer
 
Comments
Pankaj Mahor 21-Jun-14 11:02am    
Thanx it helped.
Jafarinejadvazifehkhorani 21-Jun-14 11:25am    
then mark it as an answer
Pankaj Mahor 22-Jun-14 1:41am    
It still not copy in a number sequence. Any other way plz.
You should copy parts of a big text file in several new text files, by keeping the current location of the file and when a new part will be copied to continue from that location.

For doing this you should use the method Seek() and the properties Position and Length of the FileStream class.

You could find details and examples about these properties and method in the MSDN. Here is a starting point: http://msdn.microsoft.com/en-us/library/system.io.filestream.seek(v=vs.110).aspx[^]
 
Share this answer
 
v2
Comments
Pankaj Mahor 21-Jun-14 10:30am    
Can plz u provide code?
Raul Iloc 22-Jun-14 14:53pm    
See my update above!

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