找不到路径误差对服务器的一部分 [英] Could not find a part of path error on server

查看:157
本文介绍了找不到路径误差对服务器的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每天运行的基础上调度。所以,我创建了一个 Windows应用程序,并将其存储到服务器上。



这工作得很好我的本地机器上,但我得到的路径误差




找不到路径的一部分



C\Windows\System32 ..




有了这个,我觉得可能是相关的一些路径问题。



下面是我的代码

  startupPath = Environment.CurrentDirectory。 
strExp =RAName ='+ group.Key +';

的DataTable dtNew = ds.Tables [1]。选择(strExp).CopyToDataTable();
的DataSet dsNew =新的DataSet();
dsNew.Tables.Add(dtNew);

dtNew.Columns.Remove(RAName);
dtNew.Columns.Remove(USEREMAIL);
ExcelLibrary.DataSetHelper.CreateWorkbook(startupPath +\\Attachment\\Reminder_Sheet_+ dtNew.Rows [0] [SR否]的ToString()+的.xl​​s,dsNew);

ls_attach1.Add(startupPath +\\Attachment\\Reminder_Sheet_+ dtNew.Rows [0] [SR否]的ToString()+的.xl​​s。);

的foreach(VAR在ls_attach1附后)
{
mail.Attachments.Add(新附件(附加));
}

ce.SendEmail(tb_RA.Rows [0] [RA1_Email]。的ToString(),,,关于处理文档信息,sbodyMail,
AUTOSQL,Po​​wersoft的,ls_attach1的ConnectionString);
的foreach(在mail.Attachments附件附件)
{
attachments.Dispose();
}

如果((System.IO.File.Exists(startupPath +\\Attachment\\Reminder_Sheet_+ dtNew.Rows [0] [SR否 ]的ToString()+的.xl​​s)))
{
System.IO.File.Delete(startupPath +\\Attachment\\Reminder_Sheet_+ dtNew.Rows [0 ] [SR否]的ToString()+的.xl​​s);
}



我不知道什么是错这里的路径,



下面是错误的截图




< DIV CLASS =h2_lin>解决方案

您大概都会认为,当您安装的服务,它会在那里,但是从服务安装在Windows上通过服务控制管理器运行路径上运行(SCM),它通常位于 C:\Windows\System32



所以,你的服务得到 C:\Windows\System32 CurrentPath()



您可以尝试:



startupPath = System.AppDomain.CurrentDomain.BaseDirectory;



*编辑:对于那些谁可能要检查的供应链管理的道路,那你需要检查该文件是 SC.EXE 正如 SC 您用来安装,启动,等命令。提供服务。


I want to run a scheduler on daily basis. So I have created a Windows application and stored it onto the server.

This works fine on my local machine, but I get path error as

Could not find a part of path

C\Windows\System32..

With this, I think there might be some issue related to the path.

Here is my code for that.

startupPath = Environment.CurrentDirectory;
                    strExp = "RAName = '" + group.Key + "'";

                    DataTable dtNew = ds.Tables[1].Select(strExp).CopyToDataTable();
                    DataSet dsNew = new DataSet();
                    dsNew.Tables.Add(dtNew);

                    dtNew.Columns.Remove("RAName");
                    dtNew.Columns.Remove("UserEmail");
                    ExcelLibrary.DataSetHelper.CreateWorkbook(startupPath + "\\Attachment\\Reminder_Sheet_ " + dtNew.Rows[0]["SR NO"].ToString() + ".xls", dsNew);

                    ls_attach1.Add(startupPath + "\\Attachment\\Reminder_Sheet_ " + dtNew.Rows[0]["SR NO"].ToString() + ".xls");

                    foreach (var attach in ls_attach1)
                    {
                        mail.Attachments.Add(new Attachment(attach));
                    }

                    ce.SendEmail(tb_RA.Rows[0]["RA1_Email"].ToString(), "", "", "Information on documents for processing", sbodyMail,
                                                        "AUTOSQL", "Powersoft", ls_attach1, "ConnectionString");
                    foreach (Attachment attachments in mail.Attachments)
                    {
                        attachments.Dispose();
                    }

                    if ((System.IO.File.Exists(startupPath + "\\Attachment\\Reminder_Sheet_ " + dtNew.Rows[0]["SR NO"].ToString() + ".xls")))
                    {
                        System.IO.File.Delete(startupPath + "\\Attachment\\Reminder_Sheet_ " + dtNew.Rows[0]["SR NO"].ToString() + ".xls");
                    }

I don't know what's wrong with the path here,

Here is the screenshot of the error

解决方案

You probably assumed that when you installed your service, it'd run on the path where it is installed from but services on Windows are run by "Service Control Manager" (scm) which is usually located on C:\Windows\System32

So, your service gets the C:\Windows\System32 value as CurrentPath()

You could try:

startupPath = System.AppDomain.CurrentDomain.BaseDirectory;

*Edit: For those who might want to check the path for scm, the file that you need to check is sc.exe As in sc command that you use to install,start,etc. a service.

这篇关于找不到路径误差对服务器的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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