Question

I need to make a bunch of redirect pages as I've recently updated my web site which previously used .html files and now all the files are .aspx. I have a tab-delimited file containing a list of original filenames and the corresponding new filename.

It seems like there should be a language out there that I should be able to create a file using the first column for the filename and insert the second column as its content with some additional text for the 301 redirect.

Could someone point me in the right direction as to what language(s) would be able to accomplish this? Also, if you could also point out the name of the method/function I would be using so I know where to begin when creating the file.

I've needed to do this type of thing many times and am willing to learn a new language (Perl, Python, or whatever) to accomplish this, but I just need pointed in the right direction. I am using Windows XP to develop on.

Thank you for your time.

Was it helpful?

Solution

This can be done in a few lines of C# if you already are working with aspx you can process this in the codebehind on a dummy page.

System.IO.StreamReader myreader = new System.IO.StreamReader(Server.MapPath("~/Text.txt"));
        while (!myreader.EndOfStream)
        {
            //9 is Ascii value of Tab  bad idea to split if the second set of values might contain tabs but can reconstruct the data if inputString.length >2
            string[] inputString = myreader.ReadLine().Split(char.ConvertFromUtf32(9).ToCharArray());
            //construct the path to where you want to save the file, or if the filename is the full path all the better
            System.IO.StreamWriter filemaker = new System.IO.StreamWriter(@"C:\" + inputString[0]);
            filemaker.Write(inputString[1]);
            filemaker.Close();
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top