写了一个简单的练习,从数据表中读取照片信息,存储到电脑的磁盘,系统是64位win7,总是提示exception:对路径"E:"的访问被拒绝,请问怎样解决啊
private void button1_Click(object sender, EventArgs e)
{
GetAndWriteData(@"e:\");
} private void GetAndWriteData(string path)
{
try
{
Byte[] blob = null;
FileStream fs = null;
string strCnn = "server=192.168.1.153;Initial Catalog=StudentsManageDB;UID=sa;PWD=1976421";
//string strCnn = this.ConnectString;
string strSql = "select ImageContent from tmp4";
//string strSql = "select " + this.DataFieldName + " from " + this.TableName + " where " + this.IDFieldName + " = ' " + this.FileID + " ' "; SqlConnection Cnn = new SqlConnection(strCnn);
SqlCommand Cmd = new SqlCommand(strSql, Cnn);
Cnn.Open();
SqlDataReader sReader = Cmd.ExecuteReader();
sReader.Read();
blob = new Byte[(sReader.GetBytes(0, 0, null, 0, int.MaxValue))];
sReader.GetBytes(0, 0, blob, 0, blob.Length);
sReader.Close();
Cnn.Close();
fs = new FileStream(path, FileMode.Create, FileAccess.Write); fs.Write(blob, 0, blob.Length);
fs.Close(); }
catch (SqlException ex)
{
MessageBox.Show("Sql Exception: " + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
GetAndWriteData(@"e:\");
} private void GetAndWriteData(string path)
{
try
{
Byte[] blob = null;
FileStream fs = null;
string strCnn = "server=192.168.1.153;Initial Catalog=StudentsManageDB;UID=sa;PWD=1976421";
//string strCnn = this.ConnectString;
string strSql = "select ImageContent from tmp4";
//string strSql = "select " + this.DataFieldName + " from " + this.TableName + " where " + this.IDFieldName + " = ' " + this.FileID + " ' "; SqlConnection Cnn = new SqlConnection(strCnn);
SqlCommand Cmd = new SqlCommand(strSql, Cnn);
Cnn.Open();
SqlDataReader sReader = Cmd.ExecuteReader();
sReader.Read();
blob = new Byte[(sReader.GetBytes(0, 0, null, 0, int.MaxValue))];
sReader.GetBytes(0, 0, blob, 0, blob.Length);
sReader.Close();
Cnn.Close();
fs = new FileStream(path, FileMode.Create, FileAccess.Write); fs.Write(blob, 0, blob.Length);
fs.Close(); }
catch (SqlException ex)
{
MessageBox.Show("Sql Exception: " + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
}
}
}
new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Write);
GetAndWriteData(@"e:\");
改为:
GetAndWriteData(@"e:\a.jpg");