|
I'm afraid there is no direct way to remove a line from the beginning of a file.
The only way you can do this is to overwrite the entire file with all the lines in the original file but the first one.
In case you don't know, you can use File.ReadAllLines and File.WriteAllLines to read and write lines on a file.
|
|
|
|
|
To do this, you have to do something like this:
while(true)
{
StringBuilder wholeText = "";
String fileName = "file.txt";
Textreader tr = new StreamReader(fileName);
String oneLine = tr.ReadLine();
if(oneLine == null)
{
break;
}
else
{
doSomethingWith(oneLine);
}
while(String s = tr.ReadLine != null)
{
wholeText.add(String.Format("{0}\n",s);
}
tr.Close();
Textwriter tw = new StreamWriter(fileName);
tw.write(wholeText.ToString());
tw.Close();
}
This isn't tested, but the methodoligy should work.
|
|
|
|
|
Why would you delete the line? in your scenario, when you are done, the file is empty.
You could as well use File.ReadAllLines as has been said before, but leave the lines where they are and delete the entire file (or just all its content with WriteAllText("") when done. Much easier.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Thank ya'll for your great advice. It's much appreciated. I figured out how to do it Yay!!!!! Here's the code incase anybody's interested.
private void TookMeLongEnough_Click(object sender, EventArgs e)
{
string[] lines = File.ReadAllLines(openFileDialog1.Tag.ToString());
foreach (string line in lines)
{
SaveSessionTextBox.Text = fbd.SelectedPath +
"\\" +
i++ +
"A" +
i++ +
DateTime.Now.Hour +
DateTime.Now.Minute +
DateTime.Now.Second +
DateTime.Now.Millisecond +
".spr";
}
}
foreach( inch on Jason )
{
Girlfriend.IsHappier();
}
|
|
|
|
|
some remarks anyway:
1.
jas0n23 wrote: openFileDialog1.Tag.ToString()
very strange, you use the Tag to hold a filespec?
2.
the hour/minute/sec/msec parts would be nicer with a fixed width, i.e. leading zeroes.
Try DateTime.Now.ToString("HHmmssfff")
3.
not sure why you would want two autoincrements in the filename; I would suggest
s=fbd.SelectedPath + "\\"+ i.ToString("N5")+ "_" + DateTime.Now.ToString("HHmmssfff")+".spr";
i++;
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Haha, yeah now that you mention it Luc Pattyn, it is very strange that I use .Tag to hold File Specs. But, it's just a weird preference is all. Is there any reason as to why this may be a bad thing to do?
Regards,
Jay.
foreach( inch on Jason )
{
Girlfriend.IsHappier();
}
|
|
|
|
|
Hi,
I am basically a VC++ developer but now working on C#.
I am having a assembly in that i have added a UserControl and on that UserControl I am having a tree-view control and Property Grid control. As and when user selects the different nodes I am populating the corresponding properties in that grid. For the normal properties its working perfectly. But when I have to choose the property from the drop-down list. Its creating the problem. Whenever I click on the drop-down arrow nothing happens.
So I created a test application. Took a windows form application added property grid, added a class deriving it from StringConverter. Everything works fine in test application. But I don't know why its failing in my production code.
I debugged both codes. In test application whenever I click on the drop-down arrow call is coming inside GetStandardValues function. But this is not happening in my main code, its not hitting the break-point at all.
Can anybody tell me why this is happening, Where I am going wrong?
the test application code is below. The exact code is present in my main code
namespace PropertyPage
{
class MyProperties:StringConverter
{
private double str1;
private string str2;
private string str3;
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
//return base.GetStandardValuesSupported(context);
return true;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
//return base.GetStandardValuesExclusive(context);
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(new string[] { "Entry1", "Entry2", "Entry3" });
}
[CategoryAttribute("Task "), DescriptionAttribute("test"), TypeConverter(typeof(MyProperties))]
public string Str3
{
get { return str3; }
set { str3 = value; }
}
[CategoryAttribute("Task "), DescriptionAttribute("test"), ReadOnly(true)]
public double Str1
{
get { return str1; }
set { str1 = value; }
}
[Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string Str2
{
get { return str2; }
set { str2 = value; }
}
}
}
I am initializing the grid as
private void Form1_Load(object sender, EventArgs e)
{
MyProperties my = new MyProperties();
my.Str1 = 12;
propertyGrid1.SelectedObject = my;
}
I have observed similar behavior with Str2 Property. Its not allowing me to set the path in my main code but in test application its doing its job.
|
|
|
|
|
Hi,
Please help me with your ideas for the following
1.Does .net support for WEBDAV protocol?
2.Can I implement .net remoting using WEBDAV protocol?
Right now I implemented .net remoting using TCP/IP protocol.It is working fine.I need to change this to support the WEBDAV protocol.
Please help me.
|
|
|
|
|
1. There are several third party frameworks bringing webdav-apis for .net
2. ???? AFAIK WebDav is a protocol for file-operations over web. How should this work together with remoting?
3. Please don't crosspost.
Regards
Sebastian
|
|
|
|
|
Hi,
Is it possible to display the items in a combobox in the same way windows does it when you go to open a file. If you start typing text a dropdown is displayed with files that match the text being entered.
|
|
|
|
|
hey ShivarajKumar
it is possible what you are looking for
just look at this link for the same
http://www.vbforums.com/showthread.php?p=3480955
akhilonly007@gmail.com
|
|
|
|
|
You can use AutoCompleteSource property of Combobox class.
|
|
|
|
|
Hello
I have the following code which inserts user text into a GIF image:
this.DestinationImage = new Bitmap(this.SourceImage.Width, this.SourceImage.Height, PixelFormat.Format32bppArgb);
using (Graphics graphics = Graphics.FromImage(this.DestinationImage))
{
//Draw the original image.
graphics.DrawImage(this.SourceImage, 0, 0);
//Used to write smooth text.
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
//Write the title you want.
graphics.DrawString(title, titleFont, titleBrush, left, top, StringFormat.GenericTypographic);
titleFont).Height;
//graphics.DrawString(body, bodyFont, bodyBrush, left, yTop, StringFormat.GenericTypographic);
//Free the resources.
graphics.Dispose();
}
I need to know how to animate the text (ie.- flash it, change its color, etc.)
|
|
|
|
|
Hi,
your code modifies the destination image, so if you save it with DestinationImage.Save() the file would contain both the original image and the text written on top of it; however your code does not show anything, so how could it flash?
if you want to see some animation effects on screen, you should make sure everything gets painted;
one way to do it would be to have a PictureBox that shows the original image, then use its Paint event to draw something on top of it. If you install a Windows.Forms.Timer to periodically invalidate the PB, your Paint handler would be called again and could paint something slightly different to get the animation effects you want.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Can any one please tell me how to compress a dataset and decompress it without getting a out of memory error.
Thanks in advance!
|
|
|
|
|
|
I don't want to compress the file on the hdd it must be on in the memory
|
|
|
|
|
Then you have to use a MemoryStream instead of a FileStream.
|
|
|
|
|
How to catch browser close?
I try following script but, it's accept postback events...
<script type="text/javascript">
window.onbeforeunload = function()
{
window.open('Logout.html');
}
</script>
Best Regards...
|
|
|
|
|
First: this is no javascript forum
Second: search on google for an anwser
Third: here you go:
<head>
<script language="javascript">
<!--
function LoadMe()
{
self.close();
}
</script>
</head>
<body onload="LoadMe()">
<div align="center">
<a href="javascript:window.close()">Close</a>
</div>
</body>
|
|
|
|
|
My question is "How to catch browser close ?".
It's mean how can I detect press close button on the browser.
Thanks...
|
|
|
|
|
If your question is 'how can I detect press close button on the browser' you should question that in stead of 'how to catch browser close'.
And maybe I've allready given you the anwser: <body onload="LoadMe()">
I even wrote an implementation for you, but you're probably not interested in that.
|
|
|
|
|
Thanks for care Deresen.
But I try following script but, it's accept postback events...
<script type="text/javascript">
window.onbeforeunload = function()
{
window.open('Logout.html');
}
</script>
I must be foud diffirentation between browser close and "Postback".
Thanks again...
|
|
|
|
|
What is Generic Collection?
Why we use Generic Collection?
|
|
|
|
|
Generics are like lists.
You can store some defined typed data, and then make a lot of operations like a sort, find an item, remove / add items, extract all items, etc...
|
|
|
|