'/'应用程序中的服务器错误。找不到路径的一部分 [英] Server error in '/' application. Could not find a part of the path

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

问题描述

我试图在按钮点击时删除xml文件,这些文件位于我网站上的xml文件夹中(在smarterasp.net托管中),使用以下代码:

I'm trying to delete xml files on button click , the files are in the xml folder on my site (in smarterasp.net hosting) using this code :

Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
    Dim directoryName As String = MapPath("~/xml/")
    For Each deleteFile In Directory.GetFiles(directoryName, "*.xml", SearchOption.TopDirectoryOnly)
        File.Delete(deleteFile)
    Next
    Label1.Text = "done"
End Sub





但是我收到了这个错误:



but I got this error :

Server Error in '/' Application.
Could not find a part of the path 'C:\Windows\SysWOW64\inetsrv\karary-001- 
site1.htempurl.com\xml'.
Description: An unhandled exception occurred during the execution of the 
current web request. Please review the stack trace for more information about 
the error and where it originated in the code. 

Exception Details: System.IO.DirectoryNotFoundException: Could not find a 
part of the path 'C:\Windows\SysWOW64\inetsrv\karary-001- 
site1.htempurl.com\xml'.

Source Error: 

An unhandled exception was generated during the execution of the current web 
request. Information regarding the origin and location of the exception can 
be identified using the exception stack trace below.

Stack Trace: 


[DirectoryNotFoundException: Could not find a part of the path 
'C:\Windows\SysWOW64\inetsrv\karary-001-site1.htempurl.com\xml'.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +219
System.IO.FileSystemEnumerableIterator`1.CommonInit() +268
System.IO.FileSystemEnumerableIterator`1..ctor(String path, String 
originalUserPath, String searchPattern, SearchOption searchOption, 
SearchResultHandler`1 resultHandler, Boolean checkHost) +434
System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption 
searchOption) +86
WebApplication1.addTimetable.Button4_Click(Object sender, EventArgs e) in 
C:\Users\MONZER\Desktop\Karary Web 
Site\WebApplication1\addTimetable.aspx.vb:65
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9815014
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) 
+204





我尝试过:



什么是获取文件夹的正确方法,我尝试过这些:



1- http:// karary-001-site1 .htempurl.com / xml /



2- h:\root \\\\\\\\\\\\\\\\\\ br $>


3-~ / xml /



What I have tried:

what is right way to get the folder, I have tried those :

1- http://karary-001-site1.htempurl.com/xml/

2- h:\root\home\karary-001\www\site1\xml\

3- ~/xml/

推荐答案

在ASP.NET中获取文件夹的正确方法应用程序是使用MapPath



您可能需要稍微调整一下,因为这是来自控制台应用程序,只是重新声明了FolderPath。



The right way to get the folder within an ASP.NET application is to use MapPath

You may need to adjust this a bit as this was from a console app, and just had the FolderPath redeclared.

string FolderPath = Server.MapPath("\XML");
DirectoryInfo dir = new DirectoryInfo(FolderPath);

try {
	foreach (FileInfo fi in dir.GetFiles()) {
		fi.Delete();
	}
}
catch (Exception ex) {
	MessageBox.Show(ex.Message);
}


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

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