简体   繁体   中英

Loading all files in a directory onto webpage ASP.NET

So I have the following code that is supposed to match a regular expression to the files in a directory and output all the file names that match the regular expression. However, I think my regex might be wrong. It is supposed to output files of the form [content]_[model name]_[more content], but it's currently not displaying anything.

Code:

        string pattern = @".*"+Request.QueryString["model"]+@".*";
        String myPath = HttpRuntime.AppDomainAppPath;
        var matches = Directory.GetFiles(myPath+@"All Plots 1 Year\").Where(path => Regex.Match(path, pattern).Success);
        foreach (var f in matches)
        {
            Response.Write(f);
            Response.Write("<br />");
        }

如果您的正则表达式很简单,则跳过正则表达式,跳过linq并使用>>

Directory.GetFiles(Path.Combine(myPath, @"All Plots 1 Year\"), "*" + Request.QueryString["model"] + "*")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM