Is it possible to open my Microsoft Access file with just a button click event?
The tutorials I read online has to go through OpenFileDialog but I do not want that. I want to open the file directly with a click of a button.
File Location: C:\Users\User\Documents\MedicalRecord.accdb
You can use Process.Start(), it's the same thing as double-clicking your file directly.
private void button1_Click(object sender, EventArgs e)
{
Process.Start(#"C:\Users\User\Documents\MedicalRecord.accdb");
}
Yes, it is possible, instead of using open file dialog's file name, use the file location you want
Related
I am working on a program that auto saves a Microsoft Office document after specific time (loop).
On a click of a button it will activate timer and after a given time delay it should send CTRL+S to Word and save the document.
Here is my code:
private void button1_Click(object sender, EventArgs e)
{
startTimer.Enabled = true;
stratTimer.Start();
}
private void startTimer_Tick(object sender, EventArgs e)
{
SendKeys.SendWait("^{s}");
MessageBox.Show("doc auto saved");
}
The problem is that SendKeys.Send("^{s}"); does not work.
How can I accomplish that?
SendKeys.SendWait sends keystrokes to the currently active window, so the keystrokes can be received by other window, like browser (if you are viewing this answer while the automation exe is running in the background). It is not a wise idea to send key strokes to arbitrary window.
This can partially explain why your code does not work in some cases. And it has other issues.
Just as MickyD's comment, don't use this "SendKeys" solution for automation nowadays. For auto save, VSTO is the right way to go.
See How to: Programmatically save documents.
Using the WebBrowser component in C#, is it possible to obtain the file path of a user downloaded file?
For example, a user is browsing an arbitrary website using the WebBrowser then clicks a link to download, say, a PDF. The default download manager pops-up and prompts the user to save the file and the user can download the file to a location of their choice; but I do not know where they have saved that file.
Is this actually possible using the WebBrowser control?
You can try this:
private void webBrowser1_Navigating(object sender,
WebBrowserNavigatingEventArgs e)
{
e.Cancel = true;
WebClient client = new WebClient();
client.DownloadDataCompleted += new DownloadDataCompletedEventHandler(client_DownloadDataCompleted);
client.DownloadDataAsync(e.Url);
}
void client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
string filepath = textBox1.Text;
File.WriteAllBytes(filepath, e.Result);
MessageBox.Show("File downloaded");
}
When you host the web browser component, you can handle all the events. So for example, you can handle the right click, override the menu and show your custom menu.
So When the user clicks on a link or right clicks, you can show your own dialog instead of the system dialog and then you can have the path of the downloaded file from your own dialog.
I am working on a c# Windows utility, which is opening a file using webbrowser control.
webBrowser1.Navigate("URL");
URL is actually an attachment, which is showing as "Open" "Save" dialog
private void WebBrowser1_FileDownload(Object sender, EventArgs e)
{
textbox1.text ="filedownload event fired!!"
}
can I do somthing so that i cancel the file open/save dialog in the background.
As I wanted to automate the process and don't want user to get popped up message.
I have a win forms app and I'm opening a webBrowser inside the app. I have to use the browser, since I'm automating the actual browser UI flow of the site. I hit a snag trying to upload a file. The input element type is "file" and, as I've discovered, the only way to populate it programatically is to hit the browse button and select the actual file from the "Choose File to Upload" dialog.
I found useful answers on the topic like:
Uploading Files Not Working - Need Assistance
I tried using the above solution, but my code doesn't move beyond file.InvokeMember("Click");. So basically, once the "Choose File to Upload" dialog opens, the code pauses and waits for the dialog to close. I'm not sure how to proceed from here. Would really appreciate help on this and maybe a better suggestion on dealing with <input type="file"..." elements.
I hope the following answer will help you. Add timer control to your form.
Before you invoke the click event to the upload file dialog, start the timer.
timer1.Interval = 3000;
timer1.Start();
file.InvokeMember("Click");
In the timer tick event add the following coding
private void timer1_Tick(object sender, EventArgs e)
{
try
{
timer1.Stop();
SendKeys.SendWait("D:\\testing.txt"); // enter the file path, which suppose to upload.
SendKeys.SendWait("{TAB 2}");
SendKeys.SendWait("{ENTER}");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
I want to be able to load some information programmatically into Properties.Settings.Default before I publish it, but it doesn't persist. How do I overcome that?
I have (as a test):
private void button1_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Setting1 = "abc";
Properties.Settings.Default.Save();
}
private void button2_Click(object sender, EventArgs e)
{
Text = Properties.Settings.Default.Setting1;
}
I clicked on button1, then published (with clickonce) and then run the published application and clicked on button2. The Text was empty.
If don't publish the application, rather just close it and reopen it and click on button2 – I get "abc".
See the following post http://www.codeproject.com/Articles/17659/How-To-Use-the-Settings-Class-in-C
publishing won't click the button for you.
You need to detect the setting isn't initialised correctly (compare with an application setting perhaps) and then set and save it yourself.
Blank / doesn't exist / = somesettingToUpgrade
and a little routine to find a setting by name, set and save then you could put that in the button click handler as well as say FormLoad.
It seems that the problem was that the scope was "user". But if the scope is "application" – it can't be changed programmatically.
So there seems not to be a way to do it. Persist from build programmatically, that is.