Write File and Save it as a .htm [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I Write the text file Demo.txt with Html tags i have save it as html(every time when i write it again)
this is my code...
System.IO.File.WriteAllText(#"D:\Demo.txt", string.Empty);
StreamWriter file2 = new StreamWriter(#"D:\Demo.txt", true);
int j = 0;
file2.WriteLine("<html><table border='1'>");
file2.WriteLine("<tr bgcolor='#99CCFF' >");
file2.WriteLine("</html>");
how to save it as .htm alredy having extention .txt...how to refresh text file or save it with .htm

Conditionally copy the file before or after you write to it.
if(System.IO.File.Exists("d:\Demo.txt"))
System.IO.File.Copy("d:\Demo.txt", "d:\Demo.htm", true);
http://msdn.microsoft.com/en-us/library/system.io.file.copy.aspx

Related

Image compression in machinelearning dataset

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 51 mins ago.
Improve this question
Microsoft Modelbuilder's autogenerated code suggests to load training/inference data like this:
var imageBytes = File.ReadAllBytes(path);
When I create a 100x100 bit solid colored cube in MSpaint and save it as .png and use above function to load the file I get a byte[342], while I would expect 100x100x3 bytes if it were uncompressed(?).
Am I correct to assume that the compression is intact here?
If a model is trained with compressed data, does it need similary compressed data when making predictions?
Could a model's performance improve if trained on uncompressed data?

How to create .list file in C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I know how to put string list to a .txt file for example:
//nw_TCList is a string list
string nwFinal = String.Join("\n", nw_TCList.ToArray());
System.IO.File.WriteAllText(nwPath, nwFinal);
So my question is how to put this string list file to a .list file?
-------------Question update
Thank you for all the reply, nwPath is my txt file address. (#"c:\abc\name.txt")
Problem solved! just change .txt to .list, LOL, i was thinking how to convert txt file to list file before, haha.
.list is just Extension so don't worry about that
there is direct method to write Array to file
System.IO.File.WriteAllLines(nwPath, nw_TCList);
And If you want to have .list Extension
give that in path param
E.g.
System.IO.File.WriteAllLines("D://Data.list", nw_TCList);
that did trick for me

Regex to shrink Path.Combine Relative to Absolute [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have 2 file paths:
absolute:
/Content/assets2/otherfolder/another/this/
relative:
../../../../assets/img/logo.gif
when I do Path.Combine(absolute, relative) I get:
/Content/assets2/otherfolder/another/this/../../../../assets/img/logo.gif
which works fine, but what I want to get:
/Content/assets/img/logo.gif
I need a Regex or code that removes the "../" with the corresponding folder:
/Content/assets2/otherfolder/another/this/../../../../assets/img/logo.gif
/Content/assets2/otherfolder/another/../../../assets/img/logo.gif
/Content/assets2/otherfolder/../../assets/img/logo.gif
/Content/assets2/../assets/img/logo.gif
finally into:
/Content/assets/img/logo.gif
You don't need a Regex for that. Actually, I think it would be impossible to define in a reliable way in Regex. Instead, use Path.GetFullPath:
string combined = Path.Combine(path1, path2);
string prettyPath = Path.GetFullPath(combined);

save a JPEG in progressive format [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
A similar question has already been asked on this thread:
Save JPG in progressive format
However, the answer marked is basically saying that it can't be done. However, considering it is done using other software, it definitely is something which C# can do.
Is there any way this can be done?
Magick.NET can do it with a code like this
using (MagickImage image = new MagickImage("input.png"))
{
// Set the format and write to a stream so ImageMagick won't detect the file type.
image.Format = MagickFormat.Pjpeg;
using (FileStream fs = new FileStream("output.jpg", FileMode.Create))
{
image.Write(fs);
}
// Write to .jpg file
image.Write("PJEG:output.jpg");
// Or to a .pjpeg file
image.Write("output.pjpg");
}
You can find more details here.

How do I read the names of files in a directory into an array? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I have a folder C:\MergeMe\ that is full of tab-delimited text files, but the number of files is unknown at any given time.
How do I read and store the names of the text files in the MergeMe directory into an array?
Use System.IO.Directory.GetFiles(). If you know the extension, you can, for example call:
Directory.GetFiles(#"C:\MergeMe\*.txt")
If you need other options, there are overloads that allow you to provide them.
static void Main(string[] args)
{
foreach (string file in Directory.GetFiles("MyPath"))
{
if (Path.GetExtension(file)=="youExtension")
{
using (StreamReader sr = new StreamReader(file))
{
//Your code
}
}
}
}

Categories

Resources