Winform C#中的路径有问题吗? [英] Problem with path in winform C# ?

查看:61
本文介绍了Winform C#中的路径有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我的源代码项目在磁盘E中,这是其路径: E:\ WindowsApplication1
在此文件夹中有一个文件夹Files,其路径为: E:\ WindowsApplication1 \ WindowsApplication1 \ bin \ Debug \ Files

我有一个带有浏览按钮的表单,用于选择文件,选择文件后,它将自动保存到文件夹文件"中.我选择的文件在磁盘C中: C:\ Images \ image.jpg

这是我的问题:选择文件后,发生错误:
找不到路径的一部分'' C:\ Images \ WindowsApplication1 \ bin \ Debug \ Files \ image.jpg

选择文件时如何设置默认路径?
请帮助我.

At present, my source code project is in disk E, this is its path : E:\WindowsApplication1
In this folder has a folder Files, with path : E:\WindowsApplication1\WindowsApplication1\bin\Debug\Files

I have a form with a browse button to choose file, after choose file, it will save into folder Files automatically. My chosen file is in disk C : C:\Images\image.jpg

This is my problem : after choose file, an errors occurs :
Could not find a part of the path ''C:\Images\WindowsApplication1\bin\Debug\Files\image.jpg

How can I set to default path when I chose the file?
Please help me.

推荐答案

您的代码已损坏.您需要修复您的代码.如果您发布了代码,那么我肯定可以告诉您到底是哪里出了问题.就目前情况而言,我建议在调试器中逐步执行代码,并检查用于构建此路径的变量,以查看错误.
Your code is broken. You need to fix your code. If you posted your code, I''m sure I could have told you exactly what is wrong. As it stands, I suggest stepping through your code in the debugger, and examining the variables you use to build this path, to see your error.


文件路径错误,也有问题在您的代码中.请始终在问题中包含代码,以便您快速找到解决方案.

The file path is wrong, also something wrong in your code. Please always include code in your question so that you can solutions quickly.

OP写道:

选择文件后如何设置默认路径?

How can I set to default path when I chose the file?


希望您使用的是FolderBrowserDialog,使用的是RootFolder属性.
C#中FolderBrowserDialog的示例 [


I hope you are using FolderBrowserDialog, use RootFolder property.
Example for FolderBrowserDialog in C#[^]


您的代码假定当前目录永不更改.事实并非如此.您应该始终为要使用的任何文件建立完全限定的路径.不要使用CurrentDirectory或类似的东西来查看当前目录.如果必须访问.EXE文件夹中的文件,请首先获取.EXE的路径(使用Application.StartupPath或等效文件),然后将路径信息添加到该目录.
Your code is assuming that the current directory never changes. This just isn''t the case. You should ALWAYS build fully qualified paths to any files you''re going to use. Do NOT use CurrentDirectory or some equivilent to see wha tthe current directory is. If you have to get to files in your .EXE''s folder, then get the path to the .EXE first (using Application.StartupPath or an equivilent), then add your path information to that.


这篇关于Winform C#中的路径有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆