zoukankan      html  css  js  c++  java
  • LS 存取文件

    partial void GetFile_Execute()
            {
                // Download file from selected record.
                var doc = this.DocumentsSet.SelectedItem;
                if (doc == null) return;

                Dispatchers.Main.BeginInvoke(() =>
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    string defaultFilter = "Images *.jpg, *.png, *.gif|*.jpg;*.png;*.gif|Documents *.doc, *.pdf|*.doc;*.pdf|All *.*|*.*";
                    if (!string.IsNullOrEmpty(doc.FileName))
                    {
                        string ext = Path.GetExtension(doc.FileName);
                        sfd.DefaultExt = ext;
                        defaultFilter = string.Format("*.{0}|*.{0}|", sfd.DefaultExt) + defaultFilter;
                    }
                    sfd.Filter = defaultFilter;

                    bool? selected = sfd.ShowDialog();
                    if (selected.HasValue && selected.Value)
                    {
                        string fileName = sfd.SafeFileName;
                        long len = 0;
                        using (var fs = sfd.OpenFile())
                        {
                            // Write all bytes in field to file..
                            fs.Write(doc.Blob, 0, doc.Blob.Length);
                            len = fs.Length;
                        }

                        this.ShowMessageBox("File Get: " + sfd.SafeFileName + "\nSize:" + len);

                        // Could open file if you knew the path, but SafeFileName does not give path.
                        // string path = @"c:\temp\" + fileName;
                        // var shell = AutomationFactory.CreateObject("Shell.Application");
                        // shell.ShellExecute("mspaint.exe", path, "", "open", 1);
                    }
                    else
                        this.ShowMessageBox("Cancelled");
                });
            }

            partial void EditFile_Execute()
            {
                // Upload file to selected records image field.
                var doc = this.DocumentsSet.SelectedItem;
                if (doc == null) return;

                Dispatchers.Main.BeginInvoke(() =>
                {
                    OpenFileDialog ofd = new OpenFileDialog();

                    bool? selected = ofd.ShowDialog();
                    if (selected.HasValue && selected.Value)
                    {
                        byte[] ba = null;
                        using (var fs = ofd.File.OpenRead())
                        {
                            ba = new byte[fs.Length];
                            int pos = 0;
                            while (pos < fs.Length)
                            {
                                int read = fs.Read(ba, pos, ba.Length - pos);
                                pos += read;
                            }
                            this.ShowMessageBox("File Put: " + fs.Name + "\nSize:" + fs.Length);
                        }

                        // Set document and doc name in fields. To be Saved by user.
                        doc.FileName = ofd.File.Name;
                        doc.Blob = ba;
                    }
                    else
                        this.ShowMessageBox("Cancelled");
                });
            }

  • 相关阅读:
    Ubuntu18下解决和IDEA快捷键冲突
    SM.SM图床踩坑记录
    springboot热部署
    springboot创建项目报错
    三次握手,四次挥手(转载)
    slf4j和log4j2整合报错,绑定失败
    Linux终端光标消失解决
    ssh免密登录
    Spring中编写单元测试
    用js模拟查询方法 hide() filter(":contains('"
  • 原文地址:https://www.cnblogs.com/ysharp/p/2140731.html
Copyright © 2011-2022 走看看