帮你顶一下,
我遇到类似问题,不过是win Form
用access数据库,但只能写在
Data Souce= "绝对路径"
可这样把应用程序换个目录,就找不到数据库了
VB里可以实现,直接放到同一目录下,
可C#里不知为什么不行
我遇到类似问题,不过是win Form
用access数据库,但只能写在
Data Souce= "绝对路径"
可这样把应用程序换个目录,就找不到数据库了
VB里可以实现,直接放到同一目录下,
可C#里不知为什么不行
解决方案 »
- 超链接中有“#”的文件下载 #该怎么转换
- winform设置透明度
- xml文件中有特殊符号时用load方法就出现异常
- 如何将.net程序移植到没有安装.net框架的windowsxp系统上去
- debug 和release出力文件名如何设置成不一样的名字!
- 关于上传文件的问题
- 求助:C#.NET的问题!无法调试:绑定句柄无效!
- XML文件如何修改它的属性,然后存到dataset中
- 请教班老大:你给出的“列出数据库中各表和字段的方法”的字段顺序不对?
- 我写了一个删除恢复的功能!我得到了用户删除的所有记录!但要怎么才能修改DataViewRowState状态!
- 求c#写的winform数据库程序,要有主细表或用datagrid。能给个源码多的网站就更好了。
- 怎么制作window资源文件,怎么加载他????
然后按照写xml的方法
string dir=this.Context.Parameters["targetdir"]; XmlDocument doc = new XmlDocument();
XmlNode inode;
doc.Load(dir + "\\web.config");inode = doc.DocumentElement.ChildNodes[1].ChildNodes[0];
inode.Value="ttt";
还有
this.Context.Parameters["targetdir"] -> this.Context.Parameters["TARGETDIR"]大小写牢记要区分
你确定你操作XML的方式是正确的?
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode node = doc["configuration"]["appSettings"].SelectSingleNode("add[@key=\"dsn\"]");
XmlAttribute attrValue = doc.CreateAttribute("value");
attrValue.Value = "dsnString";
node.Attributes.Append(attrValue);
doc.Save(path);
<add key="StrSqlConn" value="^SqlConnectionString^"></add>
public static void UpdateWebConfigForSqlProvider (string connectionString)
{
string webConfigFilePath = Directory.GetCurrentDirectory() + "/web/web.config";
string connectionToken = "^SqlConnectionString^";
string webConfig;
// Read the web.config file
//
StreamReader inputFile = new StreamReader(webConfigFilePath);
webConfig = inputFile.ReadToEnd();
inputFile.Close(); // Find the connection string section
//
int connectionTokenIndex = webConfig.IndexOf(connectionToken); if (connectionTokenIndex != -1)
{
// Exists, replace value
//
webConfig = webConfig.Replace(connectionToken, connectionString); } // All done, write the file back out
//
StreamWriter output = new StreamWriter(File.Open(webConfigFilePath, FileMode.Create));
output.Write(webConfig);
output.Flush();
output.Close();
}
1、这个TARGETDIR是要用户在安装的时候填写的,那么他岂不是要填写如:c:/Inetpub/wwwroot/之类的路径才行;
2、我都怀疑我的以下代码有没有运行,又不能调试???有调试的方法吗?
我是这样做的Console.Write("is running……?");,可是都没有反应?public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
Console.Write("is running……?");
string dir=this.Context.Parameters["targetdir"]; XmlDocument doc = new XmlDocument();
XmlNode inode;
doc.Load(dir + "\\web.config"); inode = doc.DocumentElement.ChildNodes[1].ChildNodes[0];
inode.Value="ttt";
}
2、这是windows程序,Console.Write("is running……?");无用。并且你的自定义代码会在所有文件已经复制完毕后才执行,相当于在最后一步执行
StreamWriter reader = new StreamWriter("c:\\test.txt");
reader.WriteLine(DateTime.Now.ToShortDateString());
reader.Close();另外,我制作的是web的安装项目呀,不能选择路径吧,只能填写一个虚拟路径,比如:test,那么也就是说TARGETDIR=“test”,这样相当于这样:doc.Load("test" + "\\web.config");
这样不行吧?
让安装程序走到最后再试(前提是你严格按照李洪根的那个文章配置了安装项目)// 只能填写一个虚拟路径,比如:test,那么也就是说TARGETDIR=“test”
wrong
IIS标识符为1的站点的主目录路径 + "test" == TARGETDIR
CustomActionData=/Virdir="[TARGETVDIR]" /Port=[PORT]
...
public override void Install(IDictionary stateSaver)
{
try
{
// Uses reflection to find the location of the config file.
System.Reflection.Assembly Asm=System.Reflection.Assembly.GetExecutingAssembly();
string strConfigLoc=Asm.Location;
string strTemp=strConfigLoc;
// Gets the parameter passed across in the CustomActionData.
string Vdir=Context.Parameters["VirDir"];//虚拟目录 strTemp =strTemp.Remove(strTemp.LastIndexOf("\\"),strTemp.Length-strTemp.LastIndexOf("\\"));
strTemp = strTemp.Remove(strTemp.LastIndexOf("\\"),strTemp.Length-strTemp.LastIndexOf("\\"));//物理目录
....
}
finally
{
}
}