这是我要更改的aspx文件中的文本行
<center><body link=blue vlink=purple class=xl65 onload="processData();"><form id="mainform"
action="http://localhost/XLEZ/DataHandler/Submit.aspx" method="post" enctype="multipart/form-
data"><input type="hidden" id="hid_extra" name="hid_extra"
value="Machine_Inspection_20140807162226.xlsx||Machine_Inspection||Excavator
Inspection||Excavator Inspection|Forklift Inspection|Tractor Inspection"/>
我的代码找到这一行,我想更改此行中表单的操作,
这是我的代码,基本上可以改变整行,但是我只想更改特定的文本
String Form_action ="http://\" + Request.Url.Authority+\"/XLEZ/DataHandler/Submit.aspx\"";
while ((line = sr.ReadLine()) != null)
{
if (line.Contains("form id=\"mainform\""))
{
index = count;
}
count++;
}
sr.Dispose();
}
if (index != 0)
{
var lines = File.ReadAllLines(selected_path);
lines[index] = Form_action ;
File.WriteAllLines(selected_path, lines);
}
但这将整个行替换为动作,我只想更改此行中的动作
在您的代码中,以下代码行显然替换了整个HTML代码行:
lines[index] = Form_action ;
您需要在此行中替换字符串的一部分。例如,您可以执行以下操作:
String Form_action ="http://\" + Request.Url.Authority+\"/XLEZ/DataHandler/Submit.aspx\"";
while ((line = sr.ReadLine()) != null)
{
if (line.Contains("form id=\"mainform\""))
{
index = count;
}
count++;
}
sr.Dispose();
}
if (index != 0)
{
var lines = File.ReadAllLines(selected_path);
int start = lines[index].IndexOf("action");
string newLine = lines[index].Substring(0, start + 8) + Form_action + " " + lines[index].Substring(lines[index].IndexOf("method"));
lines[index] = newLine;
File.WriteAllLines(selected_path, lines);
}
您的“ Form_Action”变量将没有正确的值,因为在使用Request对象之前,您已对“进行了转义。
调整后的Form-Action创建:
String Form_action ="http://" + Request.Url.Authority + "/XLEZ/DataHandler/Submit.aspx\"";
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句