另存为而不显示对话框 [英] Save as without showing dialogue box

查看:139
本文介绍了另存为而不显示对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
即时通讯使用C#Web浏览器,我想在按某个键时保存一些页面,但是当我使用SaveFileDialgue时,会弹出一个窗口并询问目的地!有没有办法直接将其保存到特定的目的地而不提示我? />
这是我的代码:

Hi guys
im using c# web browser and i want to save some of pages when a key is pressed but when i use SaveFileDialgue a window pop ups and asks for destination!is there any way to save it directly to a specific destination without prompting me?

here it is my code:

private void btnSubmit_Click(object sender, EventArgs e)
       {
           browser.Navigate("https://www.google.com/");
           SaveFileDialog sfd = new SaveFileDialog();
           sfd.Filter = " TEXT File |*.txt";
           if (sfd.ShowDialog() == DialogResult.OK)
           {
               browser.SaveDocument(sfd.FileName);
           }

       }


Tanx


Tanx

推荐答案

删除您的

Remove your

if (sfd.ShowDialog() == DialogResult.OK)


这是无需使用对话框即可直接保存文件的代码.现在,请尝试使用该文件..
This is the code for saving a file directly without using dialog box.Now try it for yours..
// create reader & open file in C drive or your location
TextWriter tr = new StreamWriter(@"C:\" + "example.txt");

// read a line of text
tr.WriteLine(richTextBox1.Text);

// close the stream
tr.Close();


这篇关于另存为而不显示对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆