473,594 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reference to external file in streamwriter

Hi,

I am trying to create a reference to an external file to write to using
stream writer and a value that is created in a for. Basically the value
that a user will create will be the name of the form.

The code below show my dilemma. The line "using (StreamWriter sw = new
StreamWriter(@" c:\{0}.txt",fmt name)) " does not work as the arguement
"fmtname" is not valid in that context. Do I need to use some string
builder routine prior to this to make the sw accept the input value as its
arguement??

private void btnOK_Click(obj ect sender, System.EventArg s e)

{

if (int.Parse(tbSt art.Text)>int.P arse(tbEnd.Text ))

MessageBox.Show ("The value in the End box is less than the Start");
double Vend =System.Convert .ToDouble(tbEnd .Text);

double Interval=System .Convert.ToDoub le(tbInterval.T ext);

double Start=System.Co nvert.ToDouble( tbStart.Text);

if ((Vend-Start) %Interval>0 )

MessageBox.Show ("The interval is not a readily divisible into the End
value");

string fmtname=tbName. Text.ToString() ;

string fmtstart=tbStar t.Text.ToString ();

string fmtend=tbEnd.Te xt.ToString();

using (StreamWriter sw = new StreamWriter(@" c:\{0}.txt",fmt name))

{

sw.WriteLine("P roc format; ");

sw.WriteLine("v alue {0}",fmtname) ;

sw.WriteLine("{ 0} - {1} = '{0} to {1}'",fmtstart, fmtend);

sw.WriteLine("; ");

sw.WriteLine("R un;");

MessageBox.Show (@"File written to c:\{0}.txt",fmt name);

}

}

thanks

Doug
Feb 23 '06 #1
2 3537
I think the problem is
using (StreamWriter sw = new StreamWriter(@" c:\{0}.txt",fmt name))
try using
using (StreamWriter sw = new StreamWriter("c :\{0}.txt",fmtn ame))
OR
string filename = String.Format(" c:\{0}.txt",fmt name);
using (StreamWriter sw = new StreamWriter(fi lename));
Sincerely,
Bobby

Feb 23 '06 #2
thanks

I tried
using (StreamWriter sw = new StreamWriter(st ring.Format(@"c :\{0}.txt",
fmtname)))

and this works perfectly

Doug

<bo*********@gm ail.com> wrote in message
news:11******** *************@i 39g2000cwa.goog legroups.com...
I think the problem is
using (StreamWriter sw = new StreamWriter(@" c:\{0}.txt",fmt name))
try using
using (StreamWriter sw = new StreamWriter("c :\{0}.txt",fmtn ame))
OR
string filename = String.Format(" c:\{0}.txt",fmt name);
using (StreamWriter sw = new StreamWriter(fi lename));
Sincerely,
Bobby

Feb 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1338
by: Philipp Sumi | last post by:
Hello all I have a thread that performs some simple I/O within a loop that runs on a separate thread. I used the using keyword to ensure the writer's disposal: using (writer) { while (myCondition) {
2
2185
by: Matt | last post by:
I have a requirement where a user upload a CSV file to the server through an ASP.NET page. After the file is uploaded the ASP.NET page then has to upload the contents of this file into an Oracle table. After the upload is complete the ASP.NET page has to call an Oracle stored procedure to process the data. All this has to be done in one go. Here is a what I did. 1. Created a simple ASP.NET page which provides the user with a file upload...
6
10207
by: Don | last post by:
I'm having problems working with a streamwriter object. After closing the streamwriter and setting it to Nothing, I try to delete the file it was writing to, but I always get the following error message: "The process cannot access the file "whatever" because it is being used by another process." I've even tried opening another file using the same streamwriter object before deleting the original file, but it's no use. Something keeps...
1
19887
by: ABCL | last post by:
Hi All, I am working on the situation where 2 different Process/Application(.net) tries to open file at the same time....Or one process is updating the file and another process tries to access it, it throws an exception. How to solave this problem? So second process can wait until first process completes its processing on the file. Thanks in advance
3
16653
by: Darrin | last post by:
I've seen a couple threads on this that did not answer my question and I could not add a post to them. I've inherited a web application that is going to be replaced in the coming months. For the time being, I would like to add the Analytics (Urchin) script to the page, but there is no common components for the 100's of pages in the site. There is however a common javascript file that is referenced from all of the pages. I would like...
3
2063
by: Ganesh Palaniappan | last post by:
We're getting following exception for the below piece of code. We're wondering how it is possible since we're having a null check for objGraphics and strokePen... Exception: System.NullReferenceException: Object reference not set to an instance of an object
0
1346
by: punjabinezzie | last post by:
I am developing an Application which currently has two XML files. One XML file with some nodes and an external entity reference to another XML file. The source XML file is being parsed using Xerces (DOM Parser), upon reaching an external entity reference node the external file being referenced does not get parsed. Instead an empty node or the current node name is substituted in place and the remaining nodes parsed from original source file...
4
6854
by: SteveT | last post by:
I have a data structure that I am writing to an XML file using XmlSerializer. XmlSerializer xSer = new XmlSerializer(typeof(MyData)); StreamWriter sw = new StreamWriter("SomeData.xml"); xSer.Serialize(sw, theData); sw.Close(); I need to add a style reference within the file that looks like this: <?xml-stylesheet type="text/xsl" href="MyStyle.xsl"?>
8
5611
by: wdh3rd | last post by:
I'm still new at C and can't solve this problem. I've looked through the FAQ and on the Web, but am not having luck. I'm getting an "undefined reference" error as well as a "Id returned 1 exit status" error. I've pared down the code to a simple example: ---------------------------------square.c ---------------------------------------------------
0
7936
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8241
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6646
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5402
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3853
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1469
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.