Search and replace text within a file using C#

Hi All,

I have a file on the server called:

C:\inetpub\wwwroot\mypage.aspx

... I have appended the code for this page.

On the fly using C#, I would like to be able to replace the code ' Text="" ' within the 1 literal control with Text="1".

Please could anyone show me how to achieve this?

Many thanks,

Rit
<%@ Page Language="C#" MasterPageFile="~/content.master" %>
<script runat="server">
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="PageID" Runat="Server">
<asp:Literal ID="litPageID" runat="server" Text=""></asp:Literal>
</asp:Content>

Open in new window

LVL 1
rito1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rito1Author Commented:
If it helps, there will not be any other Text="" attributes contained within this file.
0
Mike_MozhaevCommented:
How about:
string newContent = File.ReadAllText().Replace("Text=\"\"", "Text=\"1\"");
?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rito1Author Commented:
HI Mike_Mozhaev,

I am just checking this out.

Thanks,

Rich
0
rito1Author Commented:
Perfect, thanks.

Rit
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.