我的代码如下: [WebMethod]
public bool LoadePicture(string picName, out byte[] dsData, out string errorMsg)
{
SqlConnection conn = new SqlConnection(connstring);
try
{
DataSet dsPicture = new DataSet();
dsData = null;
conn.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter("Select * From Picture where 1<>1 ", conn);
sqlDA.Fill(dsPicture, "Picture");
DataRow r;
r = dsPicture.Tables["Picture"].NewRow();
string fileName = @"I:\" + picName + ".JPG//从网络盘(映射盘)
if (File.Exists(fileName))
{
byte[] picbyte;
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
picbyte = new byte[fs.Length];
fs.Position = 0;
fs.Read(picbyte, 0, Convert.ToInt32(fs.Length));
r["P_XT"] = picName;
r["P_Picture"] = picbyte;
dsPicture.Tables["Picture"].Rows.Add(r);
sqlDA.Dispose();
errorMsg = "";
dsData = serverbase.SerializationDataset(dsPicture);
return true;
}
else
{
errorMsg = "沒有此圖片";
dsData = null ;
return false;
}
}
catch (Exception E)
{
errorMsg = E.Message.ToString();
dsData = null;
return false;
}
finally
{
conn.Close();
}
}
如果是本地盘,一点问题也没有,是网络盘就读不到了,这句都是返回false,if (File.Exists(fileName))
为什么?有高手能解决吗?
网络盘在webservice中应如何写呢。请帮我改一改。
public bool LoadePicture(string picName, out byte[] dsData, out string errorMsg)
{
SqlConnection conn = new SqlConnection(connstring);
try
{
DataSet dsPicture = new DataSet();
dsData = null;
conn.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter("Select * From Picture where 1<>1 ", conn);
sqlDA.Fill(dsPicture, "Picture");
DataRow r;
r = dsPicture.Tables["Picture"].NewRow();
string fileName = @"I:\" + picName + ".JPG//从网络盘(映射盘)
if (File.Exists(fileName))
{
byte[] picbyte;
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
picbyte = new byte[fs.Length];
fs.Position = 0;
fs.Read(picbyte, 0, Convert.ToInt32(fs.Length));
r["P_XT"] = picName;
r["P_Picture"] = picbyte;
dsPicture.Tables["Picture"].Rows.Add(r);
sqlDA.Dispose();
errorMsg = "";
dsData = serverbase.SerializationDataset(dsPicture);
return true;
}
else
{
errorMsg = "沒有此圖片";
dsData = null ;
return false;
}
}
catch (Exception E)
{
errorMsg = E.Message.ToString();
dsData = null;
return false;
}
finally
{
conn.Close();
}
}
如果是本地盘,一点问题也没有,是网络盘就读不到了,这句都是返回false,if (File.Exists(fileName))
为什么?有高手能解决吗?
网络盘在webservice中应如何写呢。请帮我改一改。
解决方案 »
- DEV TreeList 怎么获取所有子节点
- 如何保存网格列信息
- winform datagridview 如何增加展开行
- 关于asp.net网站管理工具在哪儿登录的问题
- OpenFileDialog点取消按钮时提示错误?
- [攒分贴]每日小知识
- WebForm中web.config文件配置的问题
- 安装文件制作的问题,怎么安装后启动一个制定的程序(exe文件)
- C#删除文件的问题
- 用c#写.net如何点击一个按钮,弹出一个消息框确认,我是指在C#程序中实现
- 初学者问:vs2003中启动正常,直接运行.exe报system.outofmemoryException错误
- Richtextbox添加图片后,移动到边缘改变Cursor.
有种说法是要访问网络硬盘需要启动explorer进程,但是服务程序是不能启动该进程的。虽然我不十分理解,但是我写过服务程序里面确实也遇到这个问题,就是使用绝对地址来解决的。使用绝对路径!
不知如何在webservice下通过验证。
如果是
string path = @"\\192.168.2.1\pic\helle.jpg";File.Exists(path);你试试看,在服务里面返回应该是true的。但是:string path=@"Z:\hello.jpg";File.Exists(path)
就是false。
要解决验证如何通过的问题就可以了。IIS如何能登入@"\\192.168.2.1\pic\helle.jpg";