请问怎么在设计时, 获取到当前项目的所在的绝对路径呢? public partial class UserControl1 : UserControl{ public UserControl1() { InitializeComponent(); MessageBox.Show(Application.StartupPath); }}在设计时, 弹出的对话框是 "d:\program files\microsoft visual studio 8\common7\IDE", 可是我想获取的是项目所在位置, 应该用什么方法呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory); 弹出的路径仍然是: "d:\program files\microsoft visual studio 8\common7\IDE" 不会啊,我测试了楼主的代码,没有问题的。你写的是winform程序吗? 设计时: 组件(控件) 的 Site 不为空, 可以请求服务, 设计时服务.前提是你要了解设计时的 vs 实现,vs 实现的 project, document 就是你要的.设计时方面没走那么远,帮不了你. 因为我现在需要在设计时, 创建一个文件到项目的Properties文件夹中. 引用System.Drawing 或System.winform.Desinger 或System.Desinger具体哪个忘了...public partial class UserControl1 : UserControl{ public UserControl1() { InitializeComponent(); MessageBox.Show(Application.StartupPath); } private String projectPath; [Editor(typeof(FileNameEditor),typeof(UITypeEditor))] public String ProjectPath { get { return projectPath; } set { projectPath=value; if(Directory.Exists(projectPath)) { if(!File.Exists("要写的文件")) { using(StreamWriter sw=new StreamWriter(projectPath+"//"+"要写的文件")) { sw.Write(""); //................ } } } } }} 我原来遇到过类似的问题,如果程序中用当前路径,会导致设计器不能工作,我改成这样了,不知对你有帮助没:Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "").Replace("/obj/", "/bin/")) http://blog.csdn.net/jocklyhu/archive/2009/10/27/4735436.aspx 关于DataSet中的父、子表 关于webrequest网络利用率的问题.. 救急 我的vs2005 为何没有 system.windows 很大的麻烦 c#保存设置问题 请教俩个问题,这样的系统该怎么做? 如何把swf文件嵌入exe文件中使用? 问一个打开对话框的问题!!! split切分字符串问题 一个c#登陆界面 不忙的进来坐坐~~~~~~~~~~~~~~ 如何让窗体在其父窗体中显示 采用这种方式导出excel文件时,怎么制定sheet的名字?
MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory);
弹出的路径仍然是: "d:\program files\microsoft visual studio 8\common7\IDE"
组件(控件) 的 Site 不为空, 可以请求服务, 设计时服务.前提是你要了解设计时的 vs 实现,vs 实现的 project, document 就是你要的.设计时方面没走那么远,
帮不了你.
具体哪个忘了...public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
MessageBox.Show(Application.StartupPath);
} private String projectPath; [Editor(typeof(FileNameEditor),typeof(UITypeEditor))]
public String ProjectPath
{
get { return projectPath; }
set
{
projectPath=value;
if(Directory.Exists(projectPath))
{
if(!File.Exists("要写的文件"))
{
using(StreamWriter sw=new StreamWriter(projectPath+"//"+"要写的文件"))
{
sw.Write("");
//................
}
}
}
}
}
}
Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "").Replace("/obj/", "/bin/"))