Click here to Skip to main content
15,903,033 members
Home / Discussions / C#
   

C#

 
AnswerRe: [DllImport] questen Pin
Sean8917-May-06 11:05
Sean8917-May-06 11:05 
GeneralRe: [DllImport] questen Pin
QzRz17-May-06 20:36
QzRz17-May-06 20:36 
Questionwindows title bar Pin
gonzalesman17-May-06 7:11
gonzalesman17-May-06 7:11 
AnswerRe: windows title bar Pin
NaNg1524117-May-06 7:47
NaNg1524117-May-06 7:47 
QuestionC# struct confusion Pin
thrakazog17-May-06 6:13
thrakazog17-May-06 6:13 
AnswerRe: C# struct confusion Pin
leppie17-May-06 8:51
leppie17-May-06 8:51 
QuestionCreate windows account (user) Pin
supercali17-May-06 6:11
supercali17-May-06 6:11 
QuestionRead/Write issues asap. Pin
DeepToot17-May-06 6:00
DeepToot17-May-06 6:00 
I have an rtf file that I can creating
in some of the sections I am placing contentholders [contenthere] throughout the document.

I need to be able to open up that file and search and replace that [contentholder] with the read data.

The code I used to do this is:
<br />
FileStream swfile = new FileStream(Server.MapPath("") + fPath + filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);<br />
            <br />
//Create a mew stream to read too<br />
StreamReader sr = new StreamReader(swfile);<br />
StreamWriter sw = new StreamWriter(swfile);<br />


However, I am able to loop through the document but the original is still there when done.

here is the code I use to actually search and replace:

<br />
while(sr.Peek() >=0)<br />
			{<br />
				myContent = sr.ReadLine();				<br />
				<br />
				<br />
				if(VB.InStr(myContent, "[PROSPECT]", Microsoft.VisualBasic.CompareMethod.Text) > 0)<br />
				{<br />
					myContent += myContent.Replace("[PROSPECT]", objGCache.GetProspectName());<br />
					sw.Write(myContent);<br />
				}<br />
				else<br />
				{<br />
					if(VB.InStr(myContent, "{PROSPECT}", Microsoft.VisualBasic.CompareMethod.Text) > 0)<br />
					{<br />
						myContent += myContent.Replace("{PROSPECT}", objGCache.GetProspectName());<br />
						sw.Write(myContent);<br />
					}<br />
					else<br />
					{<br />
						if(VB.InStr(myContent, "(PROSPECT}", Microsoft.VisualBasic.CompareMethod.Text) > 0)<br />
						{<br />
							myContent += myContent.Replace("(PROSPECT)", objGCache.GetProspectName());<br />
							sw.Write(myContent);<br />
						}<br />
					}<br />
				}<br />
<br />
				if(VB.InStr(myContent, "{CONTACT NAME}", Microsoft.VisualBasic.CompareMethod.Text) > 0)<br />
				{<br />
					myContent += myContent.Replace("{CONTACT NAME}", objGCache.GetContactName());<br />
					sw.Write(myContent);<br />
				}<br />
<br />
				if(VB.InStr(myContent, "{ADDRESS}", Microsoft.VisualBasic.CompareMethod.Text) > 0)<br />
				{				<br />
					myContent += myContent.Replace("{ADDRESS}", objGCache.GetAddress1());<br />
					sw.Write(myContent);<br />
				}<br />
<br />
				if(VB.InStr(myContent, "{CITY, STATE  ZIP}", Microsoft.VisualBasic.CompareMethod.Text) > 0)<br />
				{<br />
					myContent += myContent.Replace("{CITY, STATE  ZIP}", objGCache.GetCity() + "," + objGCache.GetState() + " " + objGCache.GetZip());	<br />
					sw.Write(myContent);<br />
				}<br />
				<br />
				if(VB.InStr(myContent, "[WWH]", Microsoft.VisualBasic.CompareMethod.Text) > 0)<br />
				{<br />
					myContent = myContent.Replace("[WWH]",newcontent);<br />
					sw.Write(myContent);<br />
				}<br />
<br />
				<br />
<br />
<br />
				<br />
			}<br />



Sorry for the length and bad formatting, dont have time to look all pretty Smile | :)

If anyone could give some advice asap, that would be greatly appreciated.

Steve Welborn
Software Engineer
BitWise Solutions
AnswerRe: Read/Write issues asap. Pin
Guffa17-May-06 8:18
Guffa17-May-06 8:18 
GeneralRe: Read/Write issues asap. Pin
DeepToot18-May-06 2:44
DeepToot18-May-06 2:44 
GeneralRe: Read/Write issues asap. Pin
Guffa18-May-06 7:44
Guffa18-May-06 7:44 
GeneralRe: Read/Write issues asap. Pin
DeepToot18-May-06 7:47
DeepToot18-May-06 7:47 
QuestionExcel.XlDirection problem Pin
StyleGuide17-May-06 5:56
StyleGuide17-May-06 5:56 
QuestionDate And Time Pin
| Muhammad Waqas Butt |17-May-06 5:55
professional| Muhammad Waqas Butt |17-May-06 5:55 
AnswerRe: Date And Time Pin
NaNg1524117-May-06 6:54
NaNg1524117-May-06 6:54 
AnswerRe: Date And Time Pin
NaNg1524118-May-06 2:37
NaNg1524118-May-06 2:37 
QuestionDataGridView - row height bigger than grid's height Pin
Pedro Miguel Pereira17-May-06 5:08
Pedro Miguel Pereira17-May-06 5:08 
Question2.0 gridview Pin
fmardani17-May-06 4:48
fmardani17-May-06 4:48 
QuestionPassing enum as a parameter Pin
dayakar_dn17-May-06 4:43
dayakar_dn17-May-06 4:43 
AnswerRe: Passing enum as a parameter Pin
NaNg1524117-May-06 5:07
NaNg1524117-May-06 5:07 
QuestionToolStripComboBox problem Pin
Wjousts17-May-06 3:47
Wjousts17-May-06 3:47 
QuestionCheckbox control Pin
jackalfb17-May-06 3:31
jackalfb17-May-06 3:31 
AnswerRe: Checkbox control Pin
stancrm17-May-06 3:45
stancrm17-May-06 3:45 
GeneralRe: Checkbox control Pin
jackalfb17-May-06 4:38
jackalfb17-May-06 4:38 
GeneralRe: Checkbox control Pin
microsoc17-May-06 20:04
microsoc17-May-06 20:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.