怎样将文件保存到输出目录的上一级

king19840811 2008-12-14 09:52:49
string szFileName = Application.StartupPath + "\\userpicture\\我的图片" + szExt;
FileInfo fileInfo1 = new FileInfo(szFileName);
if (!fileInfo1.Directory.Parent.Parent.Exists)
fileInfo1.Directory.Parent.Parent.Create();
szFileName = fileInfo1.Directory.Parent.Parent.FullName + "\\userpicture\\我的图片" + szExt;
这样貌似行不能啊
...全文
185 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
gxlqssjf 2008-12-15
  • 打赏
  • 举报
回复
哇,好多意见啊,关注中
king19840811 2008-12-15
  • 打赏
  • 举报
回复
FileInfo fileInfo = new FileInfo(this.pictureopenFileDialog.FileName);
string szExt = fileInfo.Extension;

//创建一个内存位图
Bitmap bmp = new Bitmap(this.pictureBox.Image.Width, this.pictureBox.Image.Height);

//把pictureBox里面的图象绘制到内存位图上
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(this.pictureBox.Image, 0, 0);
g.Dispose();

//保存内存位图为文件
string szFileName = Application.StartupPath + "\\..\\..\\userpicture\\我的图片" + szExt;
FileInfo fileInfo1 = new FileInfo(szFileName);
if (!fileInfo1.Directory.Exists)
fileInfo1.Directory.Create();
bmp.Save(fileInfo1.Directory.FullName); GDI+ 中发生一般性错误
bmp.Dispose();

详细错误:。+ Length “fileInfo1.Length”引发了“System.IO.FileNotFoundException”类型的异常 long {System.IO.FileNotFoundException}

郭军 2008-12-14
  • 打赏
  • 举报
回复
CurrentCatlog +“..\\..\\”+ "userpicture\\我的图片" + szExt;
不可能识别不了,我读上级目录的XML,一直是这样读的,你可以跟踪一下,这个目录指到了那个地方,然后调整..\\的个数。CurrentCatlog是指的release过bin目录
GTX280 2008-12-14
  • 打赏
  • 举报
回复
没看明白楼主是要保存到哪级目录中
king19840811 2008-12-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 vpei2008 的回复:]
如果是固定的可以把文件夹路径替换掉
[/Quote]
固定的??你不会让我做的东西我一个人自己用吧。
king19840811 2008-12-14
  • 打赏
  • 举报
回复
..\\这样没用。vs根本识别不了
vpei2008 2008-12-14
  • 打赏
  • 举报
回复
如果是固定的可以把文件夹路径替换掉
郭军 2008-12-14
  • 打赏
  • 举报
回复

string CurrentCatlog;

public GeoDataManagerFrom()
{
InitializeComponent();
//保存工作目录
CurrentCatlog = Directory.GetCurrentDirectory();
}



private void button1_Click(object sender, EventArgs e)
{
string szFileName = CurrentCatlog + "..\\userpicture\\我的图片" + szExt;
FileInfo fileInfo1 = new FileInfo(szFileName);
if (!fileInfo1.Directory.Parent.Parent.Exists)
fileInfo1.Directory.Parent.Parent.Create();
}
king19840811 2008-12-14
  • 打赏
  • 举报
回复
朋友给个代码出来啊。
tianjiuxiaozi 2008-12-14
  • 打赏
  • 举报
回复
截取字符串,就能得到上级目录的路径了。用String的Substring()截
lintf1986 2008-12-14
  • 打赏
  • 举报
回复
"..\\userpicture\\我的图片"

这个不行吗

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧