我在vs2010上调试时可以在D盘输出拼的.xml文件, 为啥部署到iis后便不起作用。代码如下,是iis设置上有啥机关吗 急。。
private void uploadmz_Click(HttpContext context)
{
string UploadTime = Convert.ToString(DateTime.Today).Substring(0,10);
UploadTime = UploadTime.Replace("-", "");
DataSet ds = new DataSet();
string sql = "exec usp_upload_mz";
using (SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["COMET_0000ConnectionString"].ConnectionString))
{
SqlDataAdapter adatapter = new SqlDataAdapter();
adatapter.SelectCommand = new SqlCommand(sql, sqlcon);
adatapter.Fill(ds);
}
//ds.WriteXml(@"D:\" + UploadTime + ".xml",XmlWriteMode.IgnoreSchema);
try
{
FileStream fs = new FileStream(@"D:\upload\" + UploadTime + ".xml", FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
//开始写入
foreach (DataRow dr in ds.Tables[0].Rows)
{
sw.Write(dr[0].ToString());
}
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
}
catch(Exception e) {
System.Console.WriteLine(e.Message);
}
}
权限问题,部署时的iis账户不能些硬盘,要么新建个用户,要么给默认iis帐号赋予访问你这个文件的权限
先前已经给文件夹附了Network Service完全控制的权限 路径还需要修改吗
@Lie to me:
可以这段代码的catch里面把错误输出到一个页面看看是不是权限问题。在如果确实发生了异常,在系统日志也可以看到的
@arg: Thank you for your help.