Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6152247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:53:15+00:00 2026-05-23T19:53:15+00:00

I’ve got the following bit of code that generates a list I’m trying to

  • 0

I’ve got the following bit of code that generates a list I’m trying to process. I need to create multiple files as I go through the list.

Currently I’m getting the following error on the calls to genStream outside of the IF, (in and out of the FOREACH loop), and I’m not sure why:

The name genStream' does not exist in the current context

I’m trying to figure out how I can close the one stream, and open another in the IF statement. I tried to put a .close() before creating the new stream, and it gave me an error for using it before initializing the stream.

Here is my bit of code:

    /// <summary>
    /// Creates a file for each Genre, and writes movie info to each for the cooresponding movies
    /// </summary>
    /// <param name="cPath">Path to create HTML files in</param>
    /// <param name="mList">List of Movies to generate Genre and Movie info from</param>
    public static void WriteGenreHTML(string cPath, List<Movie> mList)
    {
        int lineID = 0;
        string tmpGen = null;
        string strHeader, strMovie, strGenre, tmpGenre = null;

        // Gets a list of unique Genres from the MovieList
        var distinctGenres = from m in mList
                             from genre in m.Genres
                             group genre by genre into genres
                             select genres.First();

        // Gets a list of Movies with the associated Genres
        var moviesWithGenre = from g in distinctGenres
                              from m in mList
                              where m.Genres.Contains(g)
                              orderby g, m.Title
                              select new { Genre = g, Movie = m };

        // Traverses list of movies creating new HTML Genre files, and writing movie info to the HTML genre files
        foreach (var m in moviesWithGenre)
        {
            // Creates new HTML file if new Genre is detected
            if (m.Genre != tmpGen)
            {
                tmpGen = m.Genre;

                // initiates streamwriter for catalog output file
                FileStream fs = new FileStream(cPath + Path.DirectorySeparatorChar + m.Genre, FileMode.Create);
                StreamWriter genStream = new StreamWriter(fs);

                // Generates header info for new file, and new Genre
                strHeader = "<style type=\"text/css\">\r\n" + "<!--\r\n" + "tr#odd {\r\n" + "   background-color:#e2e2e2;\r\n" + "  vertical-align:top;\r\n" + "}\r\n" + "\r\n" + "tr#even {\r\n" + "   vertical-align:top;\r\n" + "}\r\n" + "div#title {\r\n" + "  font-size:16px;\r\n" + "    font-weight:bold;\r\n" + "}\r\n" + "\r\n" + "div#mpaa {\r\n" + "    font-size:10px;\r\n" + "}\r\n" + "\r\n" + "div#genre {\r\n" + " font-size:12px;\r\n" + "    font-style:italic;\r\n" + "}\r\n" + "\r\n" + "div#plot {\r\n" + "   height: 63px;\r\n" + "  font-size:12px;\r\n" + "    overflow:hidden;\r\n" + "}\r\n" + "\r\n" + "div#genre_heading {\r\n" + "    height: 50px;\r\n" + "  font-size: 24px;\r\n" + "   font-weight: bold;\r\n" + " text-align: center;\r\n" + "    text-decoration: underline;\r\n" + "}\r\n" + "-->\r\n" + "</style>\r\n" + "\r\n" + "<html>\r\n" + " <body>\r\n" + "     <table>\r\n";
                strHeader += "          <tr>\r\n" + "               <td colspan=2>\r\n" + "                 <div id=\"genre_heading\">" + m.Genre + "</div>\r\n" + "                </td>\r\n" + "          </tr>\r\n" + "\r\n";

                // Writes header HTML to stream
                genStream.WriteLine(strHeader);

                Console.WriteLine();
                Console.WriteLine("Now Processing " + m.Genre);
            }

            // Generates the HTML for the Movie
            strMovie = lineID == 0 ? "          <tr id=\"odd\" style=\"page-break-inside:avoid\">\r\n" : "          <tr id=\"even\" style=\"page-break-inside:avoid\">\r\n";
            strMovie += "               <td>\r\n" + "                   <img src=\".\\images\\" + m.Movie.ImageFile + "\" width=\"75\" height=\"110\">\r\n" + "             </td>\r\n" + "              <td>\r\n" + "                   <div id=\"title\">" + m.Movie.Title + "</div>\r\n" + "                  <div id=\"mpaa\">" + m.Movie.Certification + " " + m.Movie.MPAA + "</div>\r\n" + "                  <div id=\"genre\">" + strGenre + "</div>\r\n" + "                   <div id=\"plot\">" + m.Movie.Plot + "</div>\r\n" + "                </td>\r\n" + "          </tr>\r\n";

            // Writes the HTML to the stream
            genStream.WriteLine(strMovie);
            lineID = lineID == 0 ? 1 : 0;
        }

        string closingHTML = "      </table>\r\n" + "   </body>\r\n" + "</html>";
        genStream.WriteLine(closingHTML);
        genStream.Close();
    }

Side note. I’d GREATLY appreciate it if someone could point me towards something I can use to convert the HTML files into PDFs. I tried EO, and it has a nasty “watermark”, and chokes on files over a couple MB (mine are 5-10mb+). I have WkHTMLToSharp, but I am not sure how to use it, and can’t find any documentation on how to intitialize/use it.

Thanks as always!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:53:16+00:00Added an answer on May 23, 2026 at 7:53 pm

    Declare the genStream outside of foreach loop, and then initialize it as needed within the if statement:

    StreamWriter genStream;
    
    foreach (var m in moviesWithGenre)
    {
        // Creates new HTML file if new Genre is detected
        if (m.Genre != tmpGen)
        {
            tmpGen = m.Genre;
    
            // initiates streamwriter for catalog output file
            FileStream fs = new FileStream(cPath + Path.DirectorySeparatorChar + m.Genre, FileMode.Create);
            // Set genStream to the FileStream
            genStream = new StreamWriter(fs);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.