2012-12-20 49 views
0

我有WFA旁邊結構:保存openFileDialog1.FileName到Properties.Settings

using System; 
using System.Collections.Generic; 
using System.­­­­ComponentModel; 
using Sy­­­­stem.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.IO; 
using WindowsFormsApplication1.Properties; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     List<string> urls = new List<string>(); 
     private void openToolStripMenuItem_Click(object sender, EventArgs e) 
     { 
      OpenFileDialog openFileDialog1 = new OpenFileDialog(); 
      openFileDialog1.InitialDirectory = System.Environment.CurrentDirectory; 
      openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; 
      if (openFileDialog1.ShowDialog() == DialogResult.OK) 
      { 
       urls.Clear(); 
       foreach (string url in File.ReadAllLines(openFileDialog1.FileName)) 
        urls.Add(url); 
       label2.Text = urls.Count.ToString(); 
      } 
     } 

     List<string> links = new List<string>(); 
     private void open2FileToolStripMenuItem_Click(object sender, EventArgs e) 
     { 
      OpenFileDialog open­­­­FileDialog1 = new OpenFileDialog(); 
      openFileDialog1.InitialDirectory = System.Environment.CurrentDirectory; 
      openFile­­­­Dialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; 
      if (openFileDialog1.ShowDialog() == DialogResult.OK) 
      { 
       links.Clear(); 
       foreach (string link in File.ReadAllLines(openFileDialog1.FileName)) 
        links.Add(link); 
       label4.Text = links.Count.ToString(); 
      } 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 

     } 

     private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
     { 
      Settings.Default.Save(); 
     } 
    } 
} 

設計的屏幕:

http://screenshotuploader.com/i/01/k0tpbijza.png

我需要保存到propeties.settings文件的路徑,在openFileDialog中打開。

回答

相關問題