Ejemplo n.º 1
0
        /// <summary>通过图形界面读取文件 </summary>
        public static string Read(out string fileName)
        {
            OpenFileName ofn = new OpenFileName();

            ofn.structSize   = Marshal.SizeOf(ofn);
            ofn.file         = new string(new char[256]);
            ofn.maxFile      = ofn.file.Length;
            ofn.fileTitle    = new string(new char[64]);
            ofn.maxFileTitle = ofn.fileTitle.Length;
            ofn.title        = "选择文件";
            ofn.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
            if (LocalDialog.GetOpenFileName(ofn))
            {
                fileName = ofn.fileTitle;
                using (FileStream fs = new FileStream(ofn.file, FileMode.Open, FileAccess.Read)) {
                    using (StreamReader sw = new StreamReader(fs, Encoding.UTF8)) {
                        return(sw.ReadToEnd());
                    }
                }
            }
            throw new System.Exception("用户没有选择文件");
        }
Ejemplo n.º 2
0
 public static bool GetSFN([In, Out] OpenFileName ofn)
 {
     return(GetSaveFileName(ofn));
 }
Ejemplo n.º 3
0
 public static extern bool GetSaveFileName([In, Out] OpenFileName ofn);