|
Hope this helps:
try<br />
{<br />
string fileContents;<br />
<br />
using (StreamReader sr = new StreamReader(FileName))<br />
{<br />
fileContents = sr.ReadToEnd();<br />
}<br />
return fileContents;<br />
}<br />
catch (Exception exc)<br />
{<br />
return exc.Message;<br />
}
To write contents to a file use StreamWriter instead of StreamReader .
Then use yourStreamWriterObject.Write(ContentWritten); to write the contents to a file.
Hope this is helpful enough to you.
|
|
|
|
|
If you're just moving/copying files from one place to another then File.Copy and File.Move may interest you.
|
|
|
|
|
I am having a samll problem i want to add no of days to a dte variable using c#.net. Say suppose the date variable is haveing a date 25/05/2007. If i add 7 day to it i should get 01/06/2007. Can any one help me in this regard.
thanx in advance
prashanth,
s/w Engineer,
Syfnosys.
|
|
|
|
|
hi,
adding days,months,... is not that hard. the DateTime structure provides the function for that.
just do the following:
DateTime dt = DateTime.Now; //getting present date and time
dt.AddDays(7);// adding 7 days to it
dt.AddDays(-4);// subtracting 4 days
hope this helps
regards
|
|
|
|
|
DateTime dt = new DateTime(2007, 05, 25);<br />
dt = dt.AddDays(7);
|
|
|
|
|
You can use Datetime.AddDays method
|
|
|
|
|
Bitmap bm = new Bitmap(@"c:\Hamtaro.jpg");
Graphics gr = Graphics.FromImage(bm);
gr.DrawString("Hello Graphics", new Font("Verdana", 10),
new SolidBrush(Color.Tomato), 1, 40);
Error 1 Cannot implicitly convert type 'System.Drawing.Image' to 'System.Drawing.Bitmap'. An explicit conversion exists (are you missing a cast?)
And sorry, how do you save it eventually??
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
hi,
i don't see why the code doesn't work??
i tried the code below and it worked fine.
you can use the save function to save the new image.
Bitmap bm = new Bitmap(@"c:\testimage.jpg");<br />
Graphics gr = Graphics.FromImage(bm);<br />
gr.DrawString("Hello Graphics", new Font("Verdana", 10),new SolidBrush(Color.Tomato), 1,40);<br />
gr.Dispose();<br />
bm.Save(@"c:\testimage2.jpg");
regards
|
|
|
|
|
Funny, it's working real fine now
Thank you so much 1119
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
you're still not cleaning up your resources.
using (Bitmap bm = Bitmap.FromFile(@"c:\Hamtaro.jpg")/* as Bitmap */)
{
using (Graphics gr = Graphics.FromImage(bm))
{
using (Font f = new Font("Verdana", 10))
{
gr.DrawString("HelloGraphics", f, Brushes.Red, 1, 40);
bm.Save(@"c:\Hamtaro.bmp");
}
}
}
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
It's working fine now, thanks Christian.. You are a good man
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
One more question Christian
Can you tell me how do I set the modified bitmap now to a picturebox control??
Thanks a bunch
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
Just pass it to the control. mypicturebox.Image = bm;
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks again
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
This's C# not Excel.. You have all the tools, do it yourself
My small attempt...
|
|
|
|
|
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
I got resolution problems on computers that run my Windows C# Form application. For e.g. a Label are stretched in under its matching TextBox. The problem occurs on laptops with widescreen. What can be wrong?
_____________________________
...and justice for all
APe
|
|
|
|
|
You need to check the anchor property on your controls. If they are right, they will fit to any size screen.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Yes I use Anchor. It works perfect on most computers...
_____________________________
...and justice for all
APe
|
|
|
|
|
Have you checked out the dpi settings in the display properties? These are sometimes set to a non-default value on wide screens.
Standards are great! Everybody should have one!
|
|
|
|
|
I concur.
Check your screen resolution (calculate the number of pixels in the diagonal),
and measure the diagonal (in inches). Divide resolution/diagsize and then adjust
the DPI setting (which is a percentage of 96 dpi !!) with Display Properties/Settings/
Advanced.
Example:
Dell Inspiron 17" with 1920*1200 pixels
diagonal = SQRT(1920*1920 + 1200*1200) = 2264 pixels
diagonal = 16.6 inch (measured!)
hence 2264 / 16.6 * 100/96 = 142%
When you set this value, everything on the desktop will probably shrink;
your labels with fit their intended position and size; your desktop labels might
be too small for easy reading (you may want to enlarge it through Display Properties/
Appearance/Font Size).
On the other hand most objects now get their intended size (in inches, not in pixels)
which is fine; some things will become too small, typically some web pages that
for some reason dont follow the preferred text size ("Normal", "Larger", whatever),
but instead use a fixes font size (say 8 pt).
To cope with that, I developed a simple tray tool to temporarily switch screen resolution to a 30% lower value.
Hope this helps.
|
|
|
|
|
we have a "Solver" method in Excel.
can i use that thru my C# application.
i want to do the same which the solver doing, from the code
My small attempt...
|
|
|
|
|
sujithkumarsl wrote: we have a "Solver" method in Excel.
This's C# not Excel.. You have all the tools, do it yourself
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
if you dont know the answer,you are not suppose to reply
keep ur keep silence
My small attempt...
|
|
|
|
|
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|