题
我需要做一大堆重定向页面,因为我最近更新了其先前使用.html文件和现在所有的文件都的.aspx我的网站。我有一个包含原始文件名的列表制表符分隔的文件和对应的新的文件名。
好像应该有一个语言在那里,我应该可以使用文件名中的第一列创建一个文件,并插入第二列作为其内容与301重定向一些额外的文本。
有人能指出我在正确的方向,以什么语言(S)将能够做到这一点?另外,如果您也可以指出该方法/功能我会用这样的名字,我知道在哪里创建文件时开始。
我需要做这种类型的事情很多次,我愿意去学习一门新语言(Perl,Python和或其他)来做到这一点,但我只需要指出了正确的方向。我使用Windows XP的开发上。
感谢您的时间。
解决方案
这可以在C#中的几行来完成,如果你已经与ASPX工作,就可以在一个虚拟的页面上的代码隐藏处理此。
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();
}
不隶属于 StackOverflow