C# (CSharp) Class System.IO. FileStream Code Examples

C# (CSharp) System.IO.FileStream - 30 examples found. These are the top rated real world C# (CSharp) examples of class System.IO.FileStream extracted from open source projects. You can rate examples to help us improve the quality of examples
Inheritance: Stream
Example #1
0
        static RadarColorData()
        {
            using (FileStream index = new FileStream(FileManager.GetFilePath("Radarcol.mul"), FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BinaryReader bin = new BinaryReader(index);

                // Prior to 7.0.7.1, all clients have 0x10000 colors. Newer clients have fewer colors.
                int colorCount = (int)index.Length / 2;

                for (int i = 0; i < colorCount; i++)
                {
                    uint c = bin.ReadUInt16();
                    Colors[i] = 0xFF000000 | (
                            ((((c >> 10) & 0x1F) * multiplier)) |
                            ((((c >> 5) & 0x1F) * multiplier) << 8) |
                            (((c & 0x1F) * multiplier) << 16)
                            );
                }
                // fill the remainder of the color table with non-transparent magenta.
                for (int i = colorCount; i < Colors.Length; i++)
                {
                    Colors[i] = 0xFFFF00FF;
                }

                Metrics.ReportDataRead((int)bin.BaseStream.Position);
            }
        }
Example #2
0
        public void run(string text)
        {
          iSpeechSynthesis iSpeech=  new iSpeechSynthesis(_api, _production);

           iSpeech.setVoice("usenglishfemale");
           iSpeech.setOptionalCommands("format", "mp3");
            
           TTSResult result = iSpeech.speak(text);         
            
           byte [] audioData = new byte[result.getAudioFileLength()];

           int read = 0;
           int totalRead = 0;

           while (totalRead < audioData.Length)
           {
               read = result.getStream().Read(audioData, totalRead, audioData.Length - totalRead);
               totalRead += read;
           }


           FileStream fs = new FileStream("audio.mp3", FileMode.Create);
           BinaryWriter bw = new BinaryWriter(fs);

           bw.Write(audioData, 0, audioData.Length);           

        }
Example #3
0
 public void Load(BinaryReader br, FileStream fs)
 {
     Offset = br.ReadInt32();
     Offset += 16;
     FrameCount = br.ReadInt32();
     MipWidth = br.ReadInt32();
     MipHeight = br.ReadInt32();
     StartX = br.ReadInt32();
     StartY = br.ReadInt32();
     TileCount = br.ReadUInt16();
     TotalCount = br.ReadUInt16();
     CellWidth = br.ReadUInt16();
     CellHeight = br.ReadUInt16();
     Frames = new EanFrame[TotalCount];
     long curPos = fs.Position;
     fs.Seek((long)Offset, SeekOrigin.Begin);
     for (int i = 0; i < TotalCount; i++)
     {
         Frames[i].X = br.ReadUInt16();
         Frames[i].Y = br.ReadUInt16();
         Frames[i].Width = br.ReadUInt16();
         Frames[i].Height = br.ReadUInt16();
     }
     fs.Seek((long)curPos, SeekOrigin.Begin);
 }
Example #4
0
 static void Main(string[] args)
 {
     VTDGen vg = new VTDGen();
     AutoPilot ap = new AutoPilot();
     Encoding eg = System.Text.Encoding.GetEncoding("utf-8");
     //ap.selectXPath("/*/*/*");
     AutoPilot ap2 = new AutoPilot();
     ap2.selectXPath("//@*");
     if (vg.parseFile("soap2.xml", true))
     {
         FileStream fs = new FileStream("output.xml", System.IO.FileMode.OpenOrCreate);
         VTDNav vn = vg.getNav();
         ap.bind(vn);
         ap2.bind(vn);
         //ap.evalXPath();
         int i;
         while ((i = ap2.evalXPath()) != -1)
         {
             //System.out.println("attr name ---> "+ i+ " "+vn.toString(i)+"  value ---> "+vn.toString(i+1));
             vn.overWrite(i + 1, eg.GetBytes(""));
         }
         byte[] ba = vn.getXML().getBytes();
         fs.Write(ba,0,ba.Length);
         fs.Close();
     }
 }
 //This method improves upon the naive method (stringBuffer) as ENCODING.GetString
 //allocates a new character array with every invocation, and this method bypasses
 //this by reusing the same char array.  Surprisingly in tests, this method held
 //no improvement.
 static void filestream2(string filePath, Action<string> callback)
 {
     byte[] buffer = new byte[BUFFER_SIZE];
     byte[] charBuffer = new byte[MAX_TOKEN_SIZE];
     char[] encoderBuffer = new char[ENCODING.GetMaxCharCount(MAX_TOKEN_SIZE)];
     int charIndex = 0;
     int bufferSize, encodedChars;
     using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
     {
         do
         {
             bufferSize = stream.Read(buffer, 0, BUFFER_SIZE);
             for (int i = 0; i < bufferSize; i++)
             {
                 if (scannerNoMatch(buffer[i]))
                 {
                     charBuffer[charIndex++] = buffer[i];
                 }
                 else
                 {
                     encodedChars = ENCODING.GetChars(charBuffer, 0, charIndex, encoderBuffer, 0);
                     callback(new string(encoderBuffer, 0, encodedChars));
                     charIndex = 0;
                 }
             }
         } while (bufferSize != 0);
     }
 }
 public static byte[] ReadBinaryFile(string FileName)
 {
     FileStream BinaryStream = new FileStream(FileName, FileMode.Open);
     byte[] retBytes = null;
     BinaryStream.Read(retBytes, 0, BinaryStream.Length);
     return retBytes;
 }
Example #7
0
        // use static factory methods!
        private GnuPlot(Table table)
        {
            try {
                // TODO avoid necessary write access in app directory
                using (FileStream fs = new FileStream (BinaryFile, FileMode.Create, FileAccess.Write))
                    using (BinaryWriter bw = new BinaryWriter (fs)) {
                        Table3D t3D = table as Table3D;
                        if (t3D != null)
                            WriteGnuPlotBinary (bw, t3D);
                        else
                            WriteGnuPlotBinary (bw, (Table2D)table);
                    }
            } catch (Exception ex) {
                throw new GnuPlotException ("Could not write binary data file.\n" + ex.Message);
            }
            try {
                StartProcess (table);
            } catch (System.ComponentModel.Win32Exception ex) {
                // from MSDN
                // These are the Win32 error code for file not found or access denied.
                const int ERROR_FILE_NOT_FOUND = 2;
                const int ERROR_ACCESS_DENIED = 5;

                switch (ex.NativeErrorCode) {
                case ERROR_FILE_NOT_FOUND:
                    throw new GnuPlotProcessException ("Could not find gnuplot executable path:\n" + exePath + "\n\n" + ex.Message);
                case ERROR_ACCESS_DENIED:
                    throw new GnuPlotProcessException ("Access denied, no permission to start gnuplot process!\n" + ex.Message);
                default:
                    throw new GnuPlotProcessException ("Unknown error. Could not start gnuplot process.\n" + ex.Message);
                }
            }
        }
Example #8
0
 public FileReverseReader(string path)
 {
     disposed = false;
     file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     encoding = FindEncoding(file);
     SetupCharacterStartDetector();
 }
 public void ConnectExistingStream(string path, bool readOnly = true) {
     Stream.Dispose();
     Stream = null;
     Debug.GC(true);
     Stream = new FileStream(path, FileMode.Open);
     IsReadOnly = readOnly;
 }
Example #10
0
 /// 获取token,如果存在且没过期,则直接取token
 /// <summary>
 /// 获取token,如果存在且没过期,则直接取token
 /// </summary>
 /// <returns></returns>
 public static string GetExistAccessToken()
 {
     // 读取XML文件中的数据
     string filepath = System.Web.HttpContext.Current.Server.MapPath("/XMLToken.xml");
     FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     StreamReader str = new StreamReader(fs, System.Text.Encoding.UTF8);
     XmlDocument xml = new XmlDocument();
     xml.Load(str);
     str.Close();
     str.Dispose();
     fs.Close();
     fs.Dispose();
     string Token = xml.SelectSingleNode("xml").SelectSingleNode("AccessToken").InnerText;
     DateTime AccessTokenExpires = Convert.ToDateTime(xml.SelectSingleNode("xml").SelectSingleNode("AccessExpires").InnerText);
     //如果token过期,则重新获取token
     if (DateTime.Now >= AccessTokenExpires)
     {
         AccessToken mode = Getaccess();
         //将token存到xml文件中,全局缓存
         xml.SelectSingleNode("xml").SelectSingleNode("AccessToken").InnerText = mode.access_token;
         DateTime _AccessTokenExpires = DateTime.Now.AddSeconds(mode.expires_in);
         xml.SelectSingleNode("xml").SelectSingleNode("AccessExpires").InnerText = _AccessTokenExpires.ToString();
         xml.Save(filepath);
         Token = mode.access_token;
     }
     return Token;
 }
 /// <summary>
 /// Loads materials from the specified stream.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="loadTextureImages">if set to <c>true</c> texture images
 /// will be loaded and set in the <see cref="TextureMap.Image"/> property.</param>
 /// <returns>The results of the file load.</returns>
 public static FileLoadResult<List<Material>> Load(string path, bool loadTextureImages)
 {
     //  Create a streamreader and read the data.
     using(var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
     using (var streamReader = new StreamReader(stream))
         return Read(streamReader, path, loadTextureImages);
 }
Example #12
0
        public static void Main()
        {

#if NETDUINO_MINI
            StorageDevice.MountSD("SD", SPI.SPI_module.SPI1, Pins.GPIO_PIN_13);
#else
            StorageDevice.MountSD("SD", SPI.SPI_module.SPI1, Pins.GPIO_PIN_D10);
#endif

            using (var filestream = new FileStream(@"SD\resources.txt", FileMode.Open))
            {
                StreamReader reader = new StreamReader(filestream);
                Debug.Print(reader.ReadToEnd());
                reader.Close();
            }

            using (var filestream = new FileStream(@"SD\dontpanic.txt", FileMode.Create))
            {
                StreamWriter streamWriter = new StreamWriter(filestream);
                streamWriter.WriteLine("This is a test of the SD card support on the netduino...This is only a test...");
                streamWriter.Close();
            }

            StorageDevice.Unmount("SD");
        }
Example #13
0
 public void AppendTest()
 {
     /*
      * TODO : Add proper values for
      * infile  : signed file without payload
      * outFile : file to be written
      * outFile : reference file. A working file wher payload already appended
      */
     var inFile = "";
     var outFile = "";
     var reference = "";
     var payload = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?></xml>";
     if (File.Exists(inFile))
     {
         using (var inputFile = File.OpenRead(inFile))
         {
             using (var outputFile = new FileStream(outFile, FileMode.OpenOrCreate))
             {
                 Payload.Append(inputFile, outputFile, payload);
             }
         }
         var actual = File.ReadAllBytes(outFile);
         var expected = File.ReadAllBytes(reference);
         Assert.AreEqual(expected, actual);
     }
 }
Example #14
0
        static void Main(string[] args)
        {
            FileStream filStream;
            BinaryWriter binWriter;

            Console.Write("Enter name of the file: ");
            string fileName = Console.ReadLine();
            if (File.Exists(fileName))
            {
                Console.WriteLine("File - {0} already exists!", fileName);
            }
            else
            {
                filStream = new FileStream(fileName, FileMode.CreateNew);
                binWriter = new BinaryWriter(filStream);
                decimal aValue = 2.16M;
                binWriter.Write("Sample Run");
                for (int i = 0; i < 11; i++)
                {

                    binWriter.Write(i);
                }
                binWriter.Write(aValue);

                binWriter.Close();
                filStream.Close();
                Console.WriteLine("File Created successfully");
            }

            Console.ReadKey();
        }
Example #15
0
 public static String Reader()
 {
     try
     {
         FileStream fs = new FileStream(getURL(), FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
         StreamReader r = new StreamReader(fs);
         hostsFile = r.ReadToEnd();
         r.Close();
         fs.Close();
         return hostsFile;
     }
     catch (UnauthorizedAccessException)
     {
         return "Access denied";
     }
     catch (IOException)
     {
         return "Host not found.";
     }
     catch (ArgumentException)
     {
         return "Please, enter IP Address or Host name.";
     }
     catch (Exception) { return null; }
 }
Example #16
0
 private static string DeCrypting()
 {
     var res = string.Empty;
     var file = new FileStream(Controller.GetPath(), FileMode.Open, FileAccess.Read, FileShare.None, 32, FileOptions.SequentialScan);
     var reader = new BinaryReader(file);
     var writer = new BinaryWriter(new FileStream(Processor.GetNewName(Controller.GetPath()), FileMode.Create, FileAccess.Write,
         FileShare.None, 32, FileOptions.WriteThrough));
     try
     {
         var pos = 0;
         while (pos < file.Length)
         {
             var c = reader.ReadUInt16();
             //var pow = Processor.fast_exp(c, Controller.GetKc(), Controller.GetR());
             var pow = Processor.Pows(c, Controller.GetKc(), Controller.GetR());
             if (pos < 256) res += pow + " ";
             writer.Write((byte)(pow));
             pos += 2;
         }
     }
     finally
     {
         writer.Close();
         reader.Close();
     }
     return "Decoding Complete!\n" + res;
 }
Example #17
0
        static void Main(string[] args)
        {
            //AsyncReadOneFile();

            //AsyncReadMultiplyFiles();

            FileStream fs = new FileStream(@"../../Program.cs", FileMode.Open,
               FileAccess.Read, FileShare.Read, 1024,
               FileOptions.Asynchronous);

            Byte[] data = new Byte[100];

            IAsyncResult ar = fs.BeginRead(data, 0, data.Length, null, null);

            while (!ar.IsCompleted)
            {
                Console.WriteLine("Операция не завершена, ожидайте...");
                Thread.Sleep(10);
            }

            Int32 bytesRead = fs.EndRead(ar);

            fs.Close();

            Console.WriteLine("Количество считаных байт = {0}", bytesRead);
            Console.WriteLine(Encoding.UTF8.GetString(data).Remove(0, 1));
        }
Example #18
0
 /// <summary>
 /// Запись в ЛОГ-файл
 /// </summary>
 /// <param name="str"></param>
 public void WriteToLog(string str, bool doWrite = true)
 {
     if (doWrite)
     {
         StreamWriter sw = null;
         FileStream fs = null;
         try
         {
             string curDir = AppDomain.CurrentDomain.BaseDirectory;
             fs = new FileStream(curDir + "teplouchetlog.pi", FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
             sw = new StreamWriter(fs, Encoding.Default);
             if (m_vport == null) sw.WriteLine(DateTime.Now.ToString() + ": Unknown port: adress: " + m_address + ": " + str);
             else sw.WriteLine(DateTime.Now.ToString() + ": " + m_vport.GetName() + ": adress: " + m_address + ": " + str);
             sw.Close();
             fs.Close();
         }
         catch
         {
         }
         finally
         {
             if (sw != null)
             {
                 sw.Close();
                 sw = null;
             }
             if (fs != null)
             {
                 fs.Close();
                 fs = null;
             }
         }
     }
 }
        void addConfigFile(string configFilename)
        {
            var dirName = Utils.getDirName(Utils.getFullPath(configFilename));
            addAssemblySearchPath(dirName);

            try {
                using (var xmlStream = new FileStream(configFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    var doc = new XmlDocument();
                    doc.Load(XmlReader.Create(xmlStream));
                    foreach (var tmp in doc.GetElementsByTagName("probing")) {
                        var probingElem = tmp as XmlElement;
                        if (probingElem == null)
                            continue;
                        var privatePath = probingElem.GetAttribute("privatePath");
                        if (string.IsNullOrEmpty(privatePath))
                            continue;
                        foreach (var path in privatePath.Split(';'))
                            addAssemblySearchPath(Path.Combine(dirName, path));
                    }
                }
            }
            catch (IOException) {
            }
            catch (XmlException) {
            }
        }
Example #20
0
        public Tkhd(FileStream fs)
        {
            Buffer = new byte[84];
            int bytesRead = fs.Read(Buffer, 0, Buffer.Length);
            if (bytesRead < Buffer.Length)
                return;

            int version = Buffer[0];
            int addToIndex64Bit = 0;
            if (version == 1)
                addToIndex64Bit = 8;

            TrackId = GetUInt(12 + addToIndex64Bit);
            if (version == 1)
            {
                Duration = GetUInt64(20 + addToIndex64Bit);
                addToIndex64Bit += 4;
            }
            else
            {
                Duration = GetUInt(20 + addToIndex64Bit);
            }

            Width = (uint)GetWord(76 + addToIndex64Bit); // skip decimals
            Height = (uint)GetWord(80 + addToIndex64Bit); // skip decimals
            //System.Windows.Forms.MessageBox.Show("Width: " + GetWord(76 + addToIndex64Bit).ToString() + "." + GetWord(78 + addToIndex64Bit).ToString());
            //System.Windows.Forms.MessageBox.Show("Height: " + GetWord(80 + addToIndex64Bit).ToString() + "." + GetWord(82 + addToIndex64Bit).ToString());
        }
Example #21
0
        /*
         * Append active keymaps to a given file.
         */
        public static void dump(FileStream fff)
        {
            throw new NotImplementedException();
            //int mode;
            //Keymap k;

            //if (OPT(rogue_like_commands))
            //    mode = KEYMAP_MODE_ROGUE;
            //else
            //    mode = KEYMAP_MODE_ORIG;

            //for (k = keymaps[mode]; k; k = k.next) {
            //    char buf[1024];
            //    keypress key[2] = { { 0 }, { 0 } };

            //    if (!k.user) continue;

            //    /* Encode the action */
            //    keypress_to_text(buf, sizeof(buf), k.actions, false);
            //    file_putf(fff, "A:%s\n", buf);

            //    /* Convert the key into a string */
            //    key[0] = k.key;
            //    keypress_to_text(buf, sizeof(buf), key, true);
            //    file_putf(fff, "C:%d:%s\n", mode, buf);

            //    file_putf(fff, "\n");
            //}
        }
Example #22
0
 /// <summary>
 /// Determines whether the file specified by its path is a PDF file by inspecting the first eight
 /// bytes of the data. If the file header has the form «%PDF-x.y» the function returns the version
 /// number as integer (e.g. 14 for PDF 1.4). If the file header is invalid or inaccessible
 /// for any reason, 0 is returned. The function never throws an exception. 
 /// </summary>
 public static int TestPdfFile(string path)
 {
   FileStream stream = null;
   try
   {
     int pageNumber;
     string realPath = PdfSharp.Drawing.XPdfForm.ExtractPageNumber(path, out pageNumber);
     if (File.Exists(realPath)) // prevent unwanted exceptions during debugging
     {
       stream = new FileStream(realPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
       byte[] bytes = new byte[1024];
       stream.Read(bytes, 0, 1024);
       return GetPdfFileVersion(bytes);
     }
   }
   catch { }
   finally
   {
     try
     {
       if (stream != null)
         stream.Close();
     }
     catch { }
   }
   return 0;
 }
 //Base method - most simple implementation
 static void filestream(string filePath, Action<string> callback)
 {
     byte[] buffer = new byte[BUFFER_SIZE];
     byte[] charBuffer = new byte[MAX_TOKEN_SIZE];
     int charIndex = 0;
     int bufferSize;
     using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
     {
         do
         {
             bufferSize = stream.Read(buffer, 0, BUFFER_SIZE);
             for (int i = 0; i < bufferSize; i++)
             {
                 if (scannerNoMatch(buffer[i]))
                 {
                     charBuffer[charIndex++] = buffer[i];
                 }
                 else
                 {
                     callback(ENCODING.GetString(charBuffer, 0, charIndex));
                     charIndex = 0;
                 }
             }
         } while (bufferSize != 0);
     }
 }
Example #24
0
        /// <summary>
        /// Write the data of each frame in the file.
        /// </summary>
        /// <param name="controller">Controller that represent the device.</param>
        /// <param name="path">Path of the file where the data will be write.<br/>
        /// If one already exist it will be deleted and a new empty on is created.</param>
        public void RecordData(Controller controller, String path)
        {
            if (Directory.Exists(path) == true)
            {
                String destination = path + "leapMotion.data";
                try
                {
                    if (File.Exists(destination) == true)
                        File.Delete(destination);
                    file = File.Create(destination);
                }
                catch (ArgumentException e)
                {
                    throw e;
                }
            }
            else
                throw new System.ArgumentException("Destination path doesn't exist", "path");

            BinaryWriter writer = new BinaryWriter(file);
            for (int f = 9; f >= 0; f--)
            {
                Frame frameToSerialize = controller.Frame(f);
                byte[] serialized = frameToSerialize.Serialize;
                Int32 length = serialized.Length;
                writer.Write(length);
                writer.Write(serialized);
            }
        }
		public byte[] FilenameToBytes(string filename)
		{
			byte[] data = null;

			// get the file information form the selected file
			FileInfo fInfo = new FileInfo(filename);

			// get the length of the file to see if it is possible
			// to upload it (with the standard 4 MB limit)
			long numBytes = fInfo.Length;
			double dLen = Convert.ToDouble(fInfo.Length / 1000000);

			// set up a file stream and binary reader for the
			// selected file
			FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
			BinaryReader br = new BinaryReader(fStream);

			// convert the file to a byte array
			data = br.ReadBytes((int)numBytes);
			br.Close();

			fStream.Close();
			fStream.Dispose();

			return data;
		}
	public void AddFontFile(string filename) {
		using(FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
			io.InputStream stream = vmw.common.IOUtils.ToInputStream (fs);
			awt.Font font = awt.Font.createFont(awt.Font.TRUETYPE_FONT, stream);
			AddFont(font);
		}
	}
Example #27
0
        public Mdia(FileStream fs, ulong maximumLength)
        {
            Position = (ulong)fs.Position;
            while (fs.Position < (long)maximumLength)
            {
                if (!InitializeSizeAndName(fs))
                    return;

                if (Name == "minf" && IsTextSubtitle || IsVobSubSubtitle || IsClosedCaption || IsVideo)
                {
                    UInt32 timeScale = 90000;
                    if (Mdhd != null)
                        timeScale = Mdhd.TimeScale;
                    Minf = new Minf(fs, Position, timeScale, HandlerType, this);
                }
                else if (Name == "hdlr")
                {
                    Buffer = new byte[Size - 4];
                    fs.Read(Buffer, 0, Buffer.Length);
                    HandlerType = GetString(8, 4);
                    if (Size > 25)
                        HandlerName = GetString(24, Buffer.Length - (24 + 5)); // TODO: How to find this?
                }
                else if (Name == "mdhd")
                {
                    Mdhd = new Mdhd(fs, Size);
                }
                fs.Seek((long)Position, SeekOrigin.Begin);
            }
        }
Example #28
0
 public void Write(string path)
 {
     using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Write))
     {
         Write(fs);
     }
 }
Example #29
0
 void FileClose()
 {
     fileStream.Flush();
       fileStream.Close();
       fileStream.Dispose();
       fileStream = null;
 }
Example #30
0
 public static void SaveFolderFile(IList<PathItem> folders, string path)
 {
     FileStream fileStream = null;
     StreamWriter streamWriter = null;
     try
     {
         if (folders != null)
         {
             fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
             streamWriter = new StreamWriter(fileStream);
             foreach (PathItem item in folders)
             {
                 string line = String.Format("<folder name=\"{0}\" path=\"{1}\" />", item.Name, item.Path);
                 streamWriter.WriteLine(line);
             }
             streamWriter.Close();
             streamWriter = null;
             fileStream.Close();
             fileStream = null;
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Trace.TraceError("Error saving Favorites list [{0}]:\r\n{1}\r\n{2}",path,ex.Message,ex.StackTrace);
         throw;
     }
     finally
     {
         if (streamWriter != null)
             streamWriter.Close();
         if (fileStream != null)
             fileStream.Close();
     }
    
 }