open any file chosen after specific time [closed]
I want my program to open the selected file which selected by filedialo1 after specified time any answer please
this is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
string Chosen_File = " ";
}
public void timer1_Tick(object sender, EventArgs e)
{
string Chosen_File = 开发者_如何学CopenFileDialog1.FileName;
Process.Start(Chosen_File);
timer1.Enabled = true;
}
}
}
the erroer is The system cannot find the file specified
If you want the answer emailed to you, you can tick the box below your question.
The problem you have is that you're not saving the filename.
I would also have the timer initially disabled, to prevent it trying to open a file if the user cancels the dialog box. Also, don't forget to disable the timer in its tick
event handler, otherwise the file will be opened multiple times.
string Chosen_File = null;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Chosen_File = MyDialog.FileName;
timer1.Enabled = true;
}
精彩评论