从本地文本文件到C#阅读

从本地文本文件到C#阅读

本文介绍了从本地文本文件到C#阅读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜查,只发现此信息控制台,但我在想,如果有可能我的本地机器上从文件中读取文本到code,格式化,并在屏幕上显示?我们有一些法律术语,可以定期更新一个文本文件,而不是让用户通过code筛选,我们希望只更新文本文件,并具有改变在线申请。

I have searched and only found this information for console, but I was wondering if it is possible to read text from a file on my local machine into the code, format it, and display in on screen? We have a text file with some legal jargon that can be updated periodically, and instead of having the user sift through code, we were wanting to just update the text file and have the changes apply online.

谢谢!

编辑:感谢大家的意见,这里是符合要求的编辑。该计划是在C#ASP.NET网站。我看过这个正在控制台做了很多文章,但我不知道如何使它为我工作。每个人的贡献,再次感谢。

Thanks to everyone's comments, here is an edit with the requirements. The program is in C# ASP.NET website. I have read many articles about this being done in a console, but I am not sure how to make it work for me. Thanks again for everybody's contribution.

推荐答案

在这里,你有完整的程序(ASP.net)。你必须有你的ASP.net应用程序内的App_Data文件夹中的文件。在这个应用程式的文件名在Details.txt,这是你可以App_Data文件夹内。

Here you have the complete program (ASP.net). You must have a file inside the App_Data folder inside your ASP.net app. In this App your file name "Details.txt" which is available inside your App_Data folder.

您已经HiddenField,并在你的网页一个段落可用。当那一刻形式负载I M从文本文件读取数据并填充到HiddenField控件。而在$(文件)。就绪()jQuery函数我从HiddenField填充数据段。

You have HiddenField and a paragraph available in your web page. When form load at that moment i m reading data from the textfile and populating to HiddenField control. And in $(document).ready() Jquery function i am populating data to paragraph from HiddenField.

您的.aspx页面:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="ReadFromTextFileToTextBoxWebApp._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
  <style type="text/css" >
   .details
   {
       background-color:Purple;color:yellow;top: 100px;
   }
   .txtDetails
   {
       left:150px;width:200px;height:100px;
   }
  </style>
  <script src="Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
  <script type="text/javascript" language="javascript">
      $(document).ready(function () {
          var data = $("#<%=HiddenField1.ClientID %>").val();
          $('#pTextData').text(data);
      });

</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Welcome to ASP.NET!
    </h2>
     <div>
        <asp:HiddenField ID="HiddenField1" runat="server" />
        <p id="pTextData">
        </p>
     </div>
</asp:Content>

和这里是页面背后的code:

and here is your code behind page :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace ReadFromTextFileToTextBoxWebApp
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var data = File.ReadAllText(Server.MapPath("~/App_Data/Details.txt"));
            HiddenField1.Value = data.ToString();
        }
    }
}

这篇关于从本地文本文件到C#阅读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 16:57