string strfilename = “http://192.168.2.23/bbTEMP/eee/1.bmp”;
string strMokuhyouPass = @"d:\2.bmp"; File.Copy(strfilename , strMokuhyouPass , true);我想把服务器192.168.2.23上的1.bmp文件复制到我本地的机器上。
但是按照上面的做法。老是报错。请指教下。
string strMokuhyouPass = @"d:\2.bmp"; File.Copy(strfilename , strMokuhyouPass , true);我想把服务器192.168.2.23上的1.bmp文件复制到我本地的机器上。
但是按照上面的做法。老是报错。请指教下。
然后再是BinaryWriter
具体的google下~呵呵~应该有很多
WebClient oWebClient = new WebClient();//声明
oWebClient.DownloadFile("http://localhost:2365/WebSite16/licence.jpg", @"d:\1.gif");//下载
oWebClient.Dispose();//释放
string remoteUri = "http://avatar.profile.csdn.net/E/5/A/2_feng8317.jpg";
string fileName = "1.gif", WebResource = null;
//创建一个WebClient实例
WebClient myWebClient = new WebClient();
WebResource = remoteUri + fileName;
//下载Web资源并保存到当前文件系统夹
myWebClient.DownloadFile(WebResource, fileName);
string strMokuhyouPass = “http://192.168.2.25/bbTEMP/eee/2.bmp”;
WebClient oWebClient = new WebClient();//声明
oWebClient.DownloadFile("http://localhost:2365/WebSite16/licence.jpg", "“http://192.168.2.25/bbTEMP/eee/2.bmp”; ");//下载
oWebClient.Dispose();//释放 这样可以不
public byte[] GetSBFJWj(string JLID)
{
//显示图片
myConn = new OracleConnection(connectionString);
OracleDataReader reader = null;
string m_Sql = "";
try
{
string expr = "select FJLX,FJNR from t_gjgxsbfj ";
m_Sql = expr + " where JLID = '" + JLID + "'";
OracleCommand mCmd = new OracleCommand(m_Sql, myConn);
myConn.Open();
reader = mCmd.ExecuteReader();
byte[] TTreader = null;
if (reader.Read())//有数据
{
if (reader["FJLX"].ToString() != "")
{
TTreader = (byte[])reader["FJNR"];
}
}
return TTreader;
}
catch (Exception ex)
{
throw ex;
}
finally
{
reader.Dispose();
reader.Close();
myConn.Dispose();
myConn.Close();
}
}private void savefile(string fjJLID)
{
//从数据库中读出2进制流保存文件
byte[] fjphoto = sp.GetSBFJWj(fjJLID);
if (fjphoto != null)
{
string ext = sp.fj_LXbyJLID(fjJLID);//附件类型。
//string localFilePath, fileNameExt, newFileName, FilePath;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
//设置文件类型
saveFileDialog1.Filter = "" + ext + " files(*." + ext + ")|*." + ext + "";
//设置默认文件类型显示顺序
saveFileDialog1.FilterIndex = 1;
//保存对话框是否记忆上次打开的目录
saveFileDialog1.RestoreDirectory = true;
//设置默认文件名
saveFileDialog1.FileName = sp.fj_MCbyJLID(fjJLID);//附件名称。
//点了保存按钮进入
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if (saveFileDialog1.FileName != null)
{
FileStream fs;
string filepath = saveFileDialog1.FileName.ToString();
if (System.IO.File.Exists(filepath))
{
fs = new FileStream(filepath, FileMode.Truncate);
}
else
{
fs = new FileStream(filepath, FileMode.CreateNew);
}
BinaryWriter br = new BinaryWriter(fs);
br.Write(fjphoto, 0, fjphoto.Length);
br.Close();
fs.Close();
}
}
}
else
{
MessageBox.Show("没有附件。");
}
}
附件类型和附件名称这里,我是从数据库读的,你可以直接定义
大致就这样
WebClient.DownloadFile (Uri, String) Downloads the resource with the specified URI to a local file.