如何在C#上读取文件 [英] how to read a file on c#

查看:69
本文介绍了如何在C#上读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
我如何从C#上的FILE中读取缩音字符串
i使用aps.net mvc4 ...


thnks !!!

hi!!
how i can to read a coonection string from FILE on c#
i Using aps.net mvc4...


thnks!!!

推荐答案

我假定您已将它存储在Web.Config文件中.如果是这种情况,请采用以下解决方案:

http://msdn.microsoft.com/en-us/library/ms178411.aspx [ ^ ]
I assume you have it stored in you Web.Config file. If that is the case, here is the solution:

http://msdn.microsoft.com/en-us/library/ms178411.aspx[^]



首先,您应该将连接字符串保留在应用程序的web.config文件中. 然后像这样在您的代码中获取连接字符串:


First you should keep your connectionstring in the web.config file of your application
and get the connectionstring in your code like this:

string connStr=ConfigurationManager.ConnectionStrings["myConnection"].ToString();


这里的myConnection是web.config文件中ConnectionString的名称.

如果将连接字符串存储在系统上的任何其他文件中,则可以像
那样获得它


here myConnection is the name of ConnectionString in web.config file.

and if you store the connection string in any other file on your system then get it like

string connStr = File.ReadAllText("myFile.txt");


但是第二种方法不是一个好方法.


but the second one is not a good way.


这篇关于如何在C#上读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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