日期:2014-05-18  浏览次数:21189 次

WPF桌面程序中怎么打开文件,打开文件夹,和保存文件
如题

------解决方案--------------------
跟winform里面一样,都是调用.net类库里面的这些类
------解决方案--------------------
用法一样的,LZ
------解决方案--------------------
http://blog.csdn.net/johnsuna/archive/2007/08/30/1765822.aspx
------解决方案--------------------
http://www.cnblogs.com/pdfw/archive/2009/03/26/1422178.html
------解决方案--------------------
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/f91ba9d2-a8b5-46be-a37c-81d60bdc4291/
------解决方案--------------------
和WinForm差不多,就那几个类

打开文件
C# code

OpenFileDialog dlg; = new OpenFileDialog();
            dlg.FileName = "图片";
            dlg.DefaultExt = "*.*";
            dlg.Filter = "全部文件(.*)|*.*|bmp文件(.bmp)|*.bmp|jpg文件(.jpg)|*.jpg|gif文件(.gif)|*.gif|png文件(.png)|*.png|ico文件(.ico)|*.ico";
            Nullable<bool> result = dlg.ShowDialog();
            if (result == true)
            {
                filePath.Text = "图片路径:" + dlg.FileName;
                sort.IsEnabled = true;
            }

------解决方案--------------------
一样操作
WPF 控件
按钮:Button 和 RepeatButton。
对话框:OpenFileDialog、PrintDialog 和 SaveFileDialog。
参考
------解决方案--------------------
这是我最近做的,传输文件的时候,先打开窗口
C# code

        private void btnSendFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                txtMessage.Text = ofd.FileName;
                fullfilename = ofd.FileName;
                filename = fullfilename.Substring(fullfilename.LastIndexOf("\\") + 1);

                FileStream filestreamlength = new FileStream(fullfilename, FileMode.Open, FileAccess.Read);

                string sendMessageFile = "receivefile|" + filename + "|" + filestreamlength.Length.ToString() + "|";
                byte[] byteFile=new byte[1024];
                byteFile = Encoding.Unicode.GetBytes(sendMessageFile);

                clientSocket.BeginSendTo(byteFile, 0, byteFile.Length, 
                    SocketFlags.None, epServer, new AsyncCallback(OnSend), null);

                filestreamlength.Close();
                txtMessage.Text = string.Empty;
            }
        }

------解决方案--------------------
项目中选择"引用"
找到:system.windows.forms即可.