有一种奇怪的行为,我不明白。
在我的问题中,这部分代码是隐含的。
public static NpgsqlConnection ConnectRead()
{
string pass = "password_here";
StreamReader sr = new StreamReader(@"Stc.cts");
string line;
string conn = "";
while ((line = sr.ReadLine()) != null)
{
conn = line;
}
sr.Close();
conn = Cdf.Cdf.Crypt.Decrypt(conn, pass);
NpgsqlConnection con = new NpgsqlConnection(conn);
con.Open();
return con;
}和
if (mailCheckBox.Checked == true)
{
string subject = pototal;
string body = "Voici le bon de commande";
MapiMailMessage message = new MapiMailMessage(subject, body);
//message.Files.Add(serveur + nomfichier);
message.Files.Add(@"c:\pdftemp\" + nomfichier);
message.ShowDialog();
}如您所见,第一部分是连接字符串,第二部分是打开默认邮件软件的mapi。
我的问题是:如果我不使用我的程序的mapi部分,一切都会很完美。如果我使用mapi部分,我的程序将停止连接,因为它似乎将Stc.cts路径更改为c:/foxmail/Stc.cts。
如果有人有线索,我会很感激的。
发布于 2016-05-26 15:12:29
似乎您的代码使用的是相对路径。您应该提供一个绝对路径,以防有什么东西改变“当前”目录。
例如,如果您的文件与可执行文件位于相同的路径上,则可以这样做:
string strAppDir = Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
// or...
// string strAppDir = AppDomain.CurrentDomain.BaseDirectory;
string strFullPathToMyFile = System.IO.Path.Combine(strAppDir, "Stc.cts");
StreamReader sr = new StreamReader(strFullPathToMyFile);https://stackoverflow.com/questions/37462445
复制相似问题