读书人

接收文件后自动命名及保存到指定文件夹

发布时间: 2013-01-08 14:02:14 作者: rapoo

接收文件后自动命名及保存到指定文件夹中的问题

我想让它自动保存,不要弹窗出来提示保存,
这是我一开始有弹出保存提示的代码
if (arrMsgRec[0] == 1)//表示收到的是文件
{
SaveFileDialog sfd = new SaveFileDialog();
if(sfd.ShowDialog(this)==System.Windows.Forms.DialogResult.OK)

{
string fileSavePath=sfd.FileName ;//获得文件保存路径


using (FileStream fs=new FileStream (fileSavePath ,FileMode.Create ))
{
fs.Write (arrMsgRec ,1,length-1);

ShowMsg("文件保存成功:"+fileSavePath );
}
}
}


然后我修改的是在开头加上
static string fileSavePath = Application.StartupPath + "\\save\\"; //保存至Save文件夹中
这个语句,然后代码修改为
if (arrMsgRec[0] == 1)//表示收到的是文件
{

using (FileStream fs=new FileStream (fileSavePath ,FileMode.Create ))
{
fs.Write (arrMsgRec ,1,length-1);

ShowMsg("文件保存成功:"+fileSavePath );


}

}
弹出来的呃提示是接收文件后自动命名及保存到指定文件夹中的有关问题
是不是因为我没有给文件命名而导致无法存到文件夹中?怎么直接将收到的文件进行命名呢(我想以收到文件时间的分,秒对文件进行命名)???求救啊!!谢谢
[解决办法]
using (FileStream fs=new FileStream (fileSavePath ,FileMode.Create ))
{
fs.Write (arrMsgRec ,1,length-1);

ShowMsg("文件保存成功:"+fileSavePath );
}

前面需要在fileSavePath后面再追加个文件名,你的只是路径没有文件名

读书人网 >C#

热点推荐