writing file in wpf RRS feed

  • Question

  • I'm getting strange result while writing a file through my wpf app. i'm trying to serialize a an object and writing into a binary file, here's my code which writes file and m able to read it as long as application is running( and file doesn't shows in Explorer and once application is closed file also doesn't exists


    Stream s = File.OpenWrite("Data.bin");                    
                        BinaryFormatter bf = new BinaryFormatter();
                        System.Data.Generics.Data dt = new System.Data.Generics.Data();
                        dt.con = StringEncryptor.Encrypt(string.Format(DataBaseUtility.setConString,txtIns.Text,txtPath.Text));
                        bf.Serialize(s, dt);
                        MessageBox.Show("Successfully installed Database");

    The strange thing is that if i replace


     dt.con = StringEncryptor.Encrypt(string.Format(DataBaseUtility.setConString,txtIns.Text,txtPath.Text));<br/><br/>


     dt.con = StringEncryptor.Encrypt(string.Format(DataBaseUtility.setConString,"hi","Hello"));<br/><br/>It starts working<br/>


    A little Correction. txtPath is textbox which contains a file path opened by an OpenfileDialog. I checked file is being written but in the folder which contains the file opened by Openfile dialog box.


    Regards Kumar Gaurav.

    • Edited by urprob Thursday, December 22, 2011 1:32 PM
    Thursday, December 22, 2011 1:22 PM

All replies

  • Though My problem have been resolved by using System.Windows.Forms.OpenFileDialog instead of Microsoft.Win32.OpenFileDialog, But still i'm curious to know about the reason behind this, Please answer

    Regards Kumar Gaurav.
    Thursday, December 22, 2011 1:42 PM
  • Hi urprob,

    First, check out if the input text of txtIns and txtPath has the correct format. I think this is the most possible cause.
    If the above suggestion does not work, should you expose the internal implementation of System.Data.Generics.Data, DataBaseUtility.setConString. If you do not provide these, how do you expect that we can reproduce your issue?
    Thanks for your understanding.
    Have a nice day, 

    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Friday, December 23, 2011 5:34 AM
  • Sir, I'm taking name of sqlinstance (.\sqlexpress in my case) int txtIns and path of sql database (e:\temp\data\catmansys.mdf in my case) in txtPath.

    System.Data.Generics.Data is a serializable class having One field named Con which contains connectionstrin of mssql

    DataBaseUtility.setConString is a property hich gives a string format
    public static string setConString
    return @"Data Source={0};AttachDbFilename={1};Integrated Security=True;User Instance=True";

    Regards Kumar Gaurav.
    Friday, December 23, 2011 1:25 PM
  • And I've just noticed that StringEncryptor.Encrypt method could not be found in the MSDN libraries either, I suppose it is a method written by you. Should you give the definition of this method to us?
    Or for fear of any further unclear parts, should you upload a similar test project to a public place for us to download and reproduce your issue?
    Thanks for your understanding.

    Have a nice day, 

    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Monday, December 26, 2011 9:18 AM