|
I find that the following code can be helpful. This class creates a temporary file that you can use, which is removed once you dispose the instantiating class.
; public class TempFile : IDisposable
{
private string _fileName;
private bool disposed = false;
public TempFile()
{
_fileName = Path.GetTempFileName();
}
public string FileName
{
get { return _fileName; }
}
#region IDisposable Members
public void Dispose()
{
Dispose(true);
}
protected void Dispose(bool dispose)
{
if (dispose && !disposed)
{
if (File.Exists(_fileName))
{
try
{
File.Delete(_fileName);
}
catch (IOException ex)
{
Trace.WriteLine(string.Format("Unable to remove temporary file because of {0}",
ex.Message));
}
}
disposed = true;
GC.SuppressFinalize(this);
}
}
#endregion
} using (TempFile tempFile = new TempFile())
{
filename = tempFile.FileName;
using (FileStream fs = new FileStream(tempFile.FileName, FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.WriteLine("Write to temp.");
}
fs.Close();
}
Console.WriteLine("The size of {0} is {1} bytes", tempFile.FileName,
new FileInfo(tempFile.FileName).Length);
}
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
To add to the 2 other answers, in .NET 2.0, there are new constructors added to System.IO.FileStream . 2 of them take a FileOption argument (can be bitwised). One of the members of this enumeration is DeleteOnClose . I leave as an excercise for you to figure out what this does
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
Hi All,
Can any one help me how to implement paging with the datalist,
Backend database MySQL 5.0
Thanks for all.
chandu
chandu
chandu
|
|
|
|
|
|
I tryed impleminting but it was not much of use.
chandu
|
|
|
|
|
Sounds likely that the problem was a human interface error.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: a human interface error
PEBKAC?
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi,
Its working fine. You must try for that.
Thanks,
Sun Rays
|
|
|
|
|
how i can make form at run time like design time .
i mean can select Object and show properties as Textbox , Labal.
123
|
|
|
|
|
you can't, not easily. You could use reflection, I suppose, and build a UI that lets you click on a control and show/edit it's properties. But, it's a fair amount of work.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
thanks a lot , it's very good
123
|
|
|
|
|
You are welcome
|
|
|
|
|
Is it possible to dynamically change the value of a CSS field using C#? For example, use C# code to change the value of #subnav1{display:none;} to #subnav1{display:block;}on page load.
(I'm trying to adapt some Cold Fusion code into a ASP.NET master page and it uses CSS for drop-down menus).
|
|
|
|
|
This isn't C# specific, you can overload CSS in your html/asp page quite easily, just print
<style type="text/css">
#subnav1{display:block;}
</style>
in the <head> of your html output (after you include the regular stylesheet)
|
|
|
|
|
|
There is a great article in the web that covers this topic - http://odetocode.com/Articles/460.aspx . It`s very short and simple, yet contains a lot of usefull information. However, the code provided with that article seams to have a bug.
The problem is in the class BugStateChangedEventArgs, which is marked with [Serializable] attribute. Everything does compile, but throws exception at runtime: "Class BugStateChangedEventArgs is not marked as Serializable".
The source code is available for you here: http://home.icslab.agh.edu.pl/~martinez/WorkflowLibrary3.rar
Do you have any idea what may be wrong? Thank you very much in advance!
|
|
|
|
|
The BugStateChangedEventArgs class is marked as serializable, but it has an field of type Bug. The Bug class is NOT marked as serialiable. Either the field need to be marked with the NonSerializedAttribute, or the Bug class needs to support serialization. The latter is probably your best bet.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Is there any RCON library in C# for game administration?
|
|
|
|
|
What game(s) is it that you want to administer?
I don't know of a library in C# for this, but I wrote some stuff ages ago to do it for Call of Duty. It's not hard you just need to send and receive UDP packets.
Regards,
Rob Philpott.
|
|
|
|
|
Games are UT2K4, MOHAA, MOhaa Spearhead, FARCRY. I am also able to write a code for MOHAASpearhead. But i want to confirm that is there a standard for sending rcon commands. E.G. in Mohaa SpearHead i sent rcon command like "0xff 0xff 0xff 0xff 0x02 rcon password status". It works fine for mohaa but not for ut2k4. IS THERE ANY STANDARD TO SEND RCON COMMANDS TO GAME SERVER?
|
|
|
|
|
Don't think so. I think it depends on what game engine is used.
Regards,
Rob Philpott.
|
|
|
|
|
Hi,
I would like to know how to retrieve the text from a link button which is within a gridview.
Thanks in advance. =)
|
|
|
|
|
As it is a LinkButton, you can specify the Oncommand like OnCommand="lnkClick" and in the code behind you can define the event
protected void lnkClick(object sender, CommandEventArgs e)
{
// your logic here
LinkButton lnkBut = (LinkButton)sender;
string str = lnkBut.Text;
}
This is untested. if you provide anything specific then I can help you..
hope this helps..
Many thanks,
Balamurugan
|
|
|
|
|
<asp:templatefield headertext="Project"
="" showheader="False">
<itemtemplate>
<asp:linkbutton id="LinkButton1"
="" runat="server" causesvalidation="false" commandname="AddLocationCode" commandargument="<%# Eval("PName") %>" text="<%#
Eval("PName") %>">
this is the coding for the link button which is inside the gridview. I will need to retrieve the value from the link button in order to update my database.
|
|
|
|