这程序在我xp电脑上可以打开openfiledialog,但在win7中打不开什么原因?这是客户端代码:
代码应该没问题的 private void ReciveMsg()
{
while (true)
{
try
{
byte[] byteMsg = new byte[1024 * 1024 * 5];
int length = sockCleint.Receive(byteMsg);
//接收到数据了
if (length > 0)
{
//接收的是字符串
if (byteMsg[0] == 0)
{
//string strMsg = Encoding.UTF8.GetString(byteMsg, 0, length);
string strMsg = Encoding.UTF8.GetString(byteMsg,1, length);
ShowMsg(strMsg);
}
//接收的是文件
else if(byteMsg[0]==1)
{
try
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = @"F:\";
if (ofd.ShowDialog() == DialogResult.OK)
{
string savePath = ofd.FileName;
using (FileStream fs = new FileStream(savePath, FileMode.Create))
{
fs.Write(byteMsg, 1, byteMsg.Length - 1);
ShowMsg("保存完毕!" + savePath);
}
}
}
catch (Exception ex)
{ ShowErro("",ex);
break;
}
}
}
}
catch (Exception ex)
{ ShowErro("",ex);
break;
}
}
}socket
代码应该没问题的 private void ReciveMsg()
{
while (true)
{
try
{
byte[] byteMsg = new byte[1024 * 1024 * 5];
int length = sockCleint.Receive(byteMsg);
//接收到数据了
if (length > 0)
{
//接收的是字符串
if (byteMsg[0] == 0)
{
//string strMsg = Encoding.UTF8.GetString(byteMsg, 0, length);
string strMsg = Encoding.UTF8.GetString(byteMsg,1, length);
ShowMsg(strMsg);
}
//接收的是文件
else if(byteMsg[0]==1)
{
try
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = @"F:\";
if (ofd.ShowDialog() == DialogResult.OK)
{
string savePath = ofd.FileName;
using (FileStream fs = new FileStream(savePath, FileMode.Create))
{
fs.Write(byteMsg, 1, byteMsg.Length - 1);
ShowMsg("保存完毕!" + savePath);
}
}
}
catch (Exception ex)
{ ShowErro("",ex);
break;
}
}
}
}
catch (Exception ex)
{ ShowErro("",ex);
break;
}
}
}socket
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货