读书人

C# 自动更新上载文件列表

发布时间: 2012-09-19 13:43:54 作者: rapoo

C# 自动更新下载文件列表
namespace UpLoad
{
public partial class DownList : Form
{
DataTable dt = null;
public DownList()
{
InitializeComponent();
}

private void DownList_Load(object sender, EventArgs e)
{
dt = getSource();
dataGridView1.DataSource = dt;
}

public DataTable getSource()
{



string url = Form1.GetSourceList(System.AppDomain.CurrentDomain.BaseDirectory + "UpXml.xml", "url")[0];
List<string> list = Form1.GetSourceList(url, "UpdateFile");
DataTable tblDatas = new DataTable("Datas");
DataColumn dc = null;
string url2 = Form1.GetSourceList(url, "ut")[0];
//赋值给dc,是便于对每一个datacolumn的操作
dc = tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
dc.AutoIncrement = true;//自动增加
dc.AutoIncrementSeed = 1;//起始为1
dc.AutoIncrementStep = 1;//步长为1
dc.AllowDBNull = false;//
dc = tblDatas.Columns.Add("name", Type.GetType("System.String"));
dc = tblDatas.Columns.Add("lenght", Type.GetType("System.String"));
dc = tblDatas.Columns.Add("url", Type.GetType("System.String"));
DataRow newRow;
for (int i = 0; i < list.Count; i++)
{
newRow = tblDatas.NewRow();
newRow["name"] = list[i];
newRow["lenght"] = list[i].ToString().Length;
newRow["url"] =url2+"//"+ list[i].ToString();
tblDatas.Rows.Add(newRow);
}
return tblDatas;
}
//设置进度条
public void setProgressBar()
{
progressBar1.Value = 0;
progressBar1.Minimum = 0;
progressBar1.Maximum = dt.Rows.Count;
progressBar1.Step = 1;
for (int i = 0; i < dt.Rows.Count; i++)
{
progressBar1.Value += 1;
WebClient client = new WebClient();
client.DownloadFile(dt.Rows[0]["url"].ToString(), dt.Rows[i]["name"].ToString());
Thread.Sleep(1000);
}
}
private void button1_Click(object sender, EventArgs e)
{
setProgressBar();
}
downlist 界面Demo
public static List<string> GetSourceList(string xmlfilePath, string nodeName)
{
XmlTextReader textReader = null;
List<string> listStr = new List<string>();
try
{
textReader = new XmlTextReader(xmlfilePath);

while (textReader.Read())
{
if (textReader.NodeType == XmlNodeType.Element && textReader.IsStartElement())
{
if (textReader.Name == nodeName)
{
listStr.Add(textReader.ReadInnerXml());
}
}


}

}
catch(Exception ee)
{
textReader.Close();
listStr.Add(ee.Message);
}
return listStr;
}
Getsourcelist 函数


但是为什么 在读取xml里面的更新文件列表时 一直出错呢?????



[解决办法]
那句报错?
[解决办法]
具体是什么报错?

读书人网 >C#

热点推荐