Monday, May 14, 2012

.NET C# Create a file and open it using Default Application Type


public static void OpenFileWithDefaultApplication(string fullfileLocationAndName, byte[] data)
{
  try
  {
    System.IO.FileStream fs =   new System.IO.FileStream(fullfileLocationAndName, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite);
      fs.Write(data, 0, data.Length - 1);
      fs.Close();
      fs.Dispose();
      System.Diagnostics.Process.Start(fullfileLocationAndName);
  }
catch (Exception ex)
   {
       MessageBox.Show("There was an error opening the file: " + ex.Message);
}
}

No comments:

Post a Comment