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 7504799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:41:34+00:00 2026-05-29T21:41:34+00:00

I am writing a prototype to programmatically get video data from a database and

  • 0

I am writing a prototype to programmatically get video data from a database and use C# to place this data into an XML manifest file. Each video is an asset element inside XML, and I am querying all the data I need from a SQLCommand.

Problem: The XML file can only hold up to 100 video assets per file, and so I need to come up with an iterator that saves 100 assets per file until I reach the end row in the database. I am using while(r.Read()), a SqlDataReader to go into the data base using a SqlCommand.

I would like to know how to go about this process of appending 100 assets per file using a certain SQLCommand and an iteration inside the reader to process all files needed.

Below is my code thus far! (Clearly I am going to have to change some things around, such as the global elements of the XML file, which need to go in every XML file created)

        protected void btnExecute_Click(object sender, EventArgs e)
    {
        //On btn click, call method to execute program and save all files in local path
        GetVideoData();
    }

    protected void GetVideoData()
    {
        string preparer = "AgencyOasis";
        string type = "VIDEO_FULL";

        XmlDocument doc = new XmlDocument();
        XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
        doc.AppendChild(docNode);

        //add global elements:
        //create parameters for each attribute in root to be replaced, and append the new root tag to empty XML doc
        XmlElement root = doc.CreateElement("publisher-upload-manifest");
        root.SetAttribute("publisher-id", tbPublisherID.Text);
        root.SetAttribute("preparer", preparer);
        doc.AppendChild(root);

        //append notify as child to root, already in doc
        if (!string.IsNullOrEmpty(tbEmail.Text)) {
            XmlElement notify = doc.CreateElement("notify");
            notify.SetAttribute("email", tbEmail.Text);
            root.AppendChild(notify);
        }

        //THE REST OF THE ELEMENTS ARE A UNIQUE CASE FOR EACH VIDEO, THEREFORE SHOULD LOOP INSIDE THE QUERY RESULT SET, PER VIDEO.

        string sql100 = "SELECT TOP 100 Location, VideoLibraryId, Title, Keywords, IsActive, Description FROM VideoLibrary";
        const string _connStringName = "SanfordVideosConnectionString";
        string dsn = ConfigurationManager.ConnectionStrings[_connStringName].ConnectionString;
        using (SqlConnection conn = new SqlConnection(dsn))
        using (SqlCommand cmd = new SqlCommand(sql100, conn))
        {
            conn.Open();
            SqlDataReader r = cmd.ExecuteReader();
            while (r.Read())
            {
                //while going through each row with above SQL command, set data to element attributes in doc for each asset
                XmlElement asset = doc.CreateElement("asset");
                asset.SetAttribute("filename", r["Location"].ToString());
                asset.SetAttribute("refid", r["VideoLibraryId"].ToString());

                // TODO: NEED ACTUAL FILE LOCATION BEFORE I CAN EXTRACT THE SIZE OF THE FILE ITSELF
                /*create new FileInfo object to get length of existing video file
                FileInfo f = new FileInfo(r["Location"].ToString());
                long f1 = f.Length;         */

                //asset.SetAttribute("size", "10");      // TODO: f1.ToString() for static value of 2nd @
                // TODO: NEED ACTUAL FILE LOCATION AGAIN FOR HASH-CODE
                //asset.SetAttribute("hash-code", "10");  //TODO: GetMD5Hash(r["Location"].ToString())
                //setting the type globally for all videos to VIDEO_FULL ensures FLV and MP4 formats
                asset.SetAttribute("type", type);
                root.AppendChild(asset);

                XmlElement title = doc.CreateElement("title");
                title.SetAttribute("name", r["Title"].ToString());
                title.SetAttribute("refid", r["VideoLibraryId"].ToString());
                title.SetAttribute("active", r["IsActive"].ToString().ToUpper());
                // TODO: CHECK TO SEE IF VIDEO-FULL-REFID IS CORRECT
                //title.SetAttribute("video-full-refid", r["Location"].ToString() + "-" + r["VideoLibraryId"].ToString());

                XmlElement shortDesc = doc.CreateElement("short-description");
                shortDesc.InnerText = GetTrimmedDescription(250, r["Description"].ToString());
                title.AppendChild(shortDesc);
                root.AppendChild(title);

                XmlElement longDesc = doc.CreateElement("long-description");
                longDesc.InnerText = GetTrimmedDescription(5000, r["Description"].ToString());
                title.AppendChild(longDesc);
                root.AppendChild(title);
            }

        }

        //TEMPORARY FILE SAVE LOCATION  TODO: SAVE MULTIPLE FILES IN LOCAL FOLDER
        //returns the directory from where the current application domain was loaded 
        //string xmlPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, inputFileName1);
        string xmlPath = Server.MapPath(txtBoxInput.Text);
        XmlTextWriter writer = new XmlTextWriter(xmlPath, null);
        writer.Formatting = Formatting.Indented;
        doc.Save(xmlPath);
    }

    //Trims long and short descriptions to max size of chars depending on max size (250 for short and 5000 for long)
    public string GetTrimmedDescription(int maxLength, string desc) {

        if (desc.Length > maxLength)
        {
            return desc.Substring(0, (maxLength - 4)) + " ...";
        }
        else
        {
            return desc;
        }

    }

Feel free to ask me any questions about the program and I’ll try my best to explain!

  • 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-29T21:41:35+00:00Added an answer on May 29, 2026 at 9:41 pm

    If I keep your code mostly as is, here is a possible solution. I have added in some comments where I refactored pieces.

    The general idea is to fetch everything (not just 100 records) and introduce a counter that tracks where you are at. Every 100 records you spit out the file and reset. After you’ve read everything you have to spit out what is remaining. Since there are multiple files created, you will also have to track that and use a different filename. I just added a file suffix. I think the code below should work for you.

        protected void btnExecute_Click(object sender, EventArgs e)
    {
        //On btn click, call method to execute program and save all files in local path
        GetVideoData();
    }
    
    protected void GetVideoData()
        {
            string type = "VIDEO_FULL";
    
            XmlDocument doc;
            XmlElement root;
            // Refactor document creation to its own function
            doc = CreateANewDoc();
            // Refactor root creation to its own function
            root = CreateANewRoot(doc);
    
            //THE REST OF THE ELEMENTS ARE A UNIQUE CASE FOR EACH VIDEO, THEREFORE SHOULD LOOP INSIDE THE QUERY RESULT SET, PER VIDEO.
    
            // remove the top 100 and fetch everything  
            string sql100 = "SELECT Location, VideoLibraryId, Title, Keywords, IsActive, Description FROM VideoLibrary";
            const string _connStringName = "SanfordVideosConnectionString";
            string dsn = ConfigurationManager.ConnectionStrings[_connStringName].ConnectionString;
            using (SqlConnection conn = new SqlConnection(dsn))
            using (SqlCommand cmd = new SqlCommand(sql100, conn))
            {
                conn.Open();
                SqlDataReader r = cmd.ExecuteReader();
    
                // declare some counters
                int counter = 0;
                int filecounter = 0;
    
                while (r.Read())
                {
                    counter++; // Increment counter
    
                    // when you hit 100, write stuff out and reset
                    if (counter == 100 )
                    {
                        filecounter++; // Increment filecounter
                        DumpOutFile(doc, filecounter);
                        // Reset counter
                        counter = 0;
                        // Reset doc
                        doc = CreateANewDoc();
                        root = CreateANewRoot(doc);
                    }
    
                    //while going through each row with above SQL command, set data to element attributes in doc for each asset
                    XmlElement asset = doc.CreateElement("asset");
                    asset.SetAttribute("filename", r["Location"].ToString());
                    asset.SetAttribute("refid", r["VideoLibraryId"].ToString());
    
                    // TODO: NEED ACTUAL FILE LOCATION BEFORE I CAN EXTRACT THE SIZE OF THE FILE ITSELF
                    /*create new FileInfo object to get length of existing video file
                    FileInfo f = new FileInfo(r["Location"].ToString());
                    long f1 = f.Length;         */
    
                    //asset.SetAttribute("size", "10");      // TODO: f1.ToString() for static value of 2nd @
                    // TODO: NEED ACTUAL FILE LOCATION AGAIN FOR HASH-CODE
                    //asset.SetAttribute("hash-code", "10");  //TODO: GetMD5Hash(r["Location"].ToString())
                    //setting the type globally for all videos to VIDEO_FULL ensures FLV and MP4 formats
                    asset.SetAttribute("type", type);
                    root.AppendChild(asset);
    
                    XmlElement title = doc.CreateElement("title");
                    title.SetAttribute("name", r["Title"].ToString());
                    title.SetAttribute("refid", r["VideoLibraryId"].ToString());
                    title.SetAttribute("active", r["IsActive"].ToString().ToUpper());
                    // TODO: CHECK TO SEE IF VIDEO-FULL-REFID IS CORRECT
                    //title.SetAttribute("video-full-refid", r["Location"].ToString() + "-" + r["VideoLibraryId"].ToString());
    
                    XmlElement shortDesc = doc.CreateElement("short-description");
                    shortDesc.InnerText = GetTrimmedDescription(250, r["Description"].ToString());
                    title.AppendChild(shortDesc);
                    root.AppendChild(title);
    
                    XmlElement longDesc = doc.CreateElement("long-description");
                    longDesc.InnerText = GetTrimmedDescription(5000, r["Description"].ToString());
                    title.AppendChild(longDesc);
                    root.AppendChild(title);
    
                }
    
                // Dump out whatever is left (handles the remainder after division by 100
                DumpOutFile(doc, filecounter + 1);
            }
    
        }
    
    //Trims long and short descriptions to max size of chars depending on max size (250 for short and 5000 for long)
    public string GetTrimmedDescription(int maxLength, string desc) {
    
        if (desc.Length > maxLength)
        {
            return desc.Substring(0, (maxLength - 4)) + " ...";
        }
        else
        {
            return desc;
        }
    
    }
    
    private XmlDocument CreateANewDoc()
    {
        XmlDocument doc = new XmlDocument();
        XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
        doc.AppendChild(docNode);
        return doc;
    }
    
    private XmlElement CreateANewRoot(XmlDocument doc)
    {
        string preparer = "AgencyOasis";
    
        //add global elements:
        //create parameters for each attribute in root to be replaced, and append the new root tag to empty XML doc
        XmlElement root = doc.CreateElement("publisher-upload-manifest");
        //root.SetAttribute("publisher-id", tbPublisherID.Text);
        root.SetAttribute("publisher-id", "tbPublisherID.Text");
        root.SetAttribute("preparer", preparer);
        doc.AppendChild(root);
    
        //append notify as child to root, already in doc
        if (!string.IsNullOrEmpty(tbEmail.Text)) {
            XmlElement notify = doc.CreateElement("notify");
            notify.SetAttribute("email", tbEmail.Text);
            root.AppendChild(notify);
        }
    
        return root;
    }
    
    private void DumpOutFile(XmlDocument doc, int filenumber)
    {
        //TEMPORARY FILE SAVE LOCATION  TODO: SAVE MULTIPLE FILES IN LOCAL FOLDER
        //returns the directory from where the current application domain was loaded 
        //string xmlPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, inputFileName1);
        string xmlPath = Server.MapPath(txtBoxInput.Text + filenumber.ToString());
        XmlTextWriter writer = new XmlTextWriter(xmlPath, null);
        writer.Formatting = Formatting.Indented;
        doc.Save(xmlPath);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a userscript for a website that uses Prototype. Rather than use the
I am writing a prototype application. Right now some things fail such as inserting
I'm writing a prototype to prove the feasibility of something I'm working on. Basically,
I'm writing a JavaSCript class that has a method that recursively calls itself. Scheduler.prototype.updateTimer
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
I am writing a simple prototype code to demonstrate & profile I/O schemes (HDF4,
I am (stuck) using Prototype 1.3.1 and I'm having a hard time moving from
I'm in the process of writing a simple prototype in Node.js with some helper
I'm writing some MVC JavaScript code using Prototype. The problem is that when I
Basically everyone writing about member enumeration in JavaScript heavily advocates the use of the

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.