{"id":230712,"date":"2021-11-25T09:58:17","date_gmt":"2021-11-25T01:58:17","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=230712"},"modified":"2021-11-24T09:58:57","modified_gmt":"2021-11-24T01:58:57","slug":"pages-file-introduction","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/pages-file-introduction.html","title":{"rendered":"ASP.NET Web Pages – \u6587\u4ef6\u7b80\u4ecb"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u7528\u6765\u5b58\u50a8\u6570\u636e\u7684\u6587\u672c\u6587\u4ef6\u901a\u5e38\u88ab\u79f0\u4e3a\u5e73\u9762\u6587\u4ef6\u3002\u5e38\u89c1\u7684\u6587\u672c\u6587\u4ef6\u683c\u5f0f\u662f .txt\u3001.xml \u548c .csv\uff08\u9017\u53f7\u5206\u9694\u503c\uff09\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u4f7f\u7528\u6587\u672c\u6587\u4ef6<\/strong><\/div>\n

\u5728\u524d\u9762\u7684\u7ae0\u8282\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u4e86\u89e3\u5230\u7f51\u9875\u6570\u636e\u662f\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u7684\u3002<\/p>\n

\u60a8\u4e5f\u53ef\u4ee5\u628a\u7ad9\u70b9\u6570\u636e\u5b58\u50a8\u5728\u6587\u672c\u6587\u4ef6\u4e2d\u3002<\/p>\n

\u7528\u6765\u5b58\u50a8\u6570\u636e\u7684\u6587\u672c\u6587\u4ef6\u901a\u5e38\u88ab\u79f0\u4e3a\u5e73\u9762\u6587\u4ef6\u3002\u5e38\u89c1\u7684\u6587\u672c\u6587\u4ef6\u683c\u5f0f\u662f .txt\u3001.xml \u548c .csv\uff08\u9017\u53f7\u5206\u9694\u503c\uff09\u3002<\/p>\n

\u5728\u672c\u7ae0\u4e2d\uff0c\u60a8\u5c06\u5b66\u4e60\u5230<\/strong>\uff1a<\/p>\n

    \n\u5982\u4f55\u4ece\u6587\u672c\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5e76\u663e\u793a\u6570\u636e<\/ol>\n
    \u624b\u52a8\u6dfb\u52a0\u4e00\u4e2a\u6587\u672c\u6587\u4ef6<\/strong><\/div>\n

    \u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u60a8\u5c06\u9700\u8981\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\u3002<\/p>\n

    \u5728\u60a8\u7684\u7f51\u7ad9\u4e0a\uff0c\u5982\u679c\u6ca1\u6709 App_Data \u6587\u4ef6\u5939\uff0c\u8bf7\u521b\u5efa\u4e00\u4e2a\u3002\u5728 App_Data \u6587\u4ef6\u5939\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a Persons.txt \u7684\u6587\u4ef6\u3002<\/p>\n

    \u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\u5230\u6587\u4ef6\u4e2d\uff1a<\/p>\n

    Persons.txt<\/strong><\/p>\n

    George,Lucas\r\nSteven,Spielberg\r\nAlfred,Hitchcock<\/pre>\n
    \u663e\u793a\u6587\u672c\u6587\u4ef6\u4e2d\u7684\u6570\u636e<\/strong><\/div>\n

    \u4e0b\u9762\u7684\u5b9e\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u663e\u793a\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\u4e2d\u7684\u6570\u636e\uff1a<\/p>\n

    \u5b9e\u4f8b<\/strong><\/p>\n

    @{
    var dataFile = Server.MapPath(\"~\/App_Data\/Persons.txt\");
    \r\nArray userData = File.ReadAllLines(dataFile);
    }

    <\/span><!DOCTYPE \r\nhtml>
    <html>
    <body>

    <h1>Reading Data from a File<\/h1>
    @foreach (string dataLine in userData)
    {
    foreach \r\n(string dataItem in dataLine.Split(','))
    {@dataItem <text>&nbsp;<\/text>}<\/span>
    \r\n<br \/>
    }<\/span>
    <\/body>
    <\/html><\/pre>\n
    \u5b9e\u4f8b\u89e3\u91ca<\/strong><\/div>\n

    \u4f7f\u7528 Server.MapPath \u627e\u5230\u786e\u5207\u7684\u6587\u672c\u6587\u4ef6\u7684\u8def\u5f84\u3002<\/p>\n

    \u4f7f\u7528 File.ReadAllLines \u6253\u5f00\u6587\u672c\u6587\u4ef6\uff0c\u5e76\u8bfb\u53d6\u6587\u4ef6\u4e2d\u7684\u6240\u6709\u884c\u5230\u4e00\u4e2a\u6570\u7ec4\u4e2d\u3002<\/p>\n

    \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u6570\u636e\u884c\u4e2d\u7684\u6570\u636e\u9879\u7684\u6570\u636e\u88ab\u663e\u793a\u3002<\/p>\n

    \u663e\u793a Excel \u6587\u4ef6\u4e2d\u7684\u6570\u636e<\/strong><\/div>\n

    \u4f7f\u7528 Microsoft Excel\uff0c\u60a8\u53ef\u4ee5\u5c06\u4e00\u4e2a\u7535\u5b50\u8868\u683c\u4fdd\u5b58\u4e3a\u4e00\u4e2a\u9017\u53f7\u5206\u9694\u7684\u6587\u672c\u6587\u4ef6\uff08.csv \u6587\u4ef6\uff09\u3002\u6b64\u65f6\uff0c\u7535\u5b50\u8868\u683c\u4e2d\u7684\u6bcf\u4e00\u884c\u4fdd\u5b58\u4e3a\u4e00\u4e2a\u6587\u672c\u884c\uff0c\u6bcf\u4e2a\u6570\u636e\u5217\u7531\u9017\u53f7\u5206\u9694\u3002<\/p>\n

    \u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0a\u9762\u7684\u5b9e\u4f8b\u8bfb\u53d6\u4e00\u4e2a Excel .csv \u6587\u4ef6\uff08\u53ea\u9700\u5c06\u6587\u4ef6\u540d\u6539\u6210\u76f8\u5e94\u7684 Excel \u6587\u4ef6\u7684\u540d\u79f0\uff09\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    \u5728\u524d\u9762\u7684\u7ae0\u8282\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u4e86\u89e3\u5230\u7f51\u9875\u6570\u636e\u662f\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u7684\u3002 \u60a8\u4e5f\u53ef\u4ee5\u628a\u7ad9\u70b9\u6570\u636e\u5b58\u50a8\u5728\u6587\u672c\u6587\u4ef6\u4e2d\u3002 \u7528\u6765\u5b58\u50a8\u6570\u636e […]<\/p>\n","protected":false},"author":1470,"featured_media":230713,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-230712","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/230712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=230712"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/230712\/revisions"}],"predecessor-version":[{"id":230719,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/230712\/revisions\/230719"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/230713"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=230712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=230712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=230712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}