我遇到异常:该进程无法访问该文件。
这是代码:
if (!Monitor.TryEnter(lockObject))
return;
try
{
watcher.EnableRaisingEvents = false;
try
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(FileName);
xdoc = null;
}
catch (XmlException xe)
{
using (StreamWriter w = File.AppendText(FileName))
{
Console.WriteLine(xe);
w.WriteLine("</test>");
w.WriteLine("</testwrapper>");
}
}
System.Threading.Thread.Sleep(2000);
XPathDocument myXPathDoc = new XPathDocument(new StreamReader(FileName, System.Text.Encoding.GetEncoding("windows-1256")));
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load("D:/GS/xsl/test.xsl");
XmlTextWriter myWriter = new XmlTextWriter(destinationFile, null);
myWriter.Formatting = Formatting.Indented;
myWriter.Indentation = 4;
myXslTrans.Transform(myXPathDoc, null, myWriter);
myWriter.Close();
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
finally
{ …Run Code Online (Sandbox Code Playgroud) 我正在读取XML文件并使用构建字符串StringBuilder.但有时我Element.Attributes会丢失,在这种情况下,字符串为null.
string key = (string)EventId.Descendants("properties").Elements("ID").Attributes("key").FirstorDefault();
Run Code Online (Sandbox Code Playgroud)
获得所有attribue值后,我正在进行字符串构建:
sb.Append(key.PadRight(33));
Run Code Online (Sandbox Code Playgroud)
但有时值key可以为null,它会产生错误:
在调用方法之前,检查以确定对象是否为null
StringBuilder即使值为null,我想追加空字符串.
运行 PowerShell 脚本时出现错误:
无法加载文件 test_new.ps1。文件 test_new.ps1 没有数字签名。
我创建了一个 CA 和一个证书,并使用这里描述的过程签署了这个文件。
这是我dir在MY目录上做的时候:
EF76B3D7D8D2406E1F2EE60CC40644B122267F18 CN=PowerShell 用户
我可以看到test_new.ps1文件末尾附加的签名块。
以下是执行政策和范围:
范围执行策略
----- ---------------
MachinePolicy 已签名
用户策略未定义
进程绕过
当前用户全部签名
本地机器未定义
machinepolicy 应优先设置为AllSigned. 一切似乎都很好,为什么我仍然收到数字签名错误。
在C#程序中,我从XML接收一个值,然后我需要针对一个数组进行测试.如果在数组中找到该值,则返回true,否则返回false.这是代码:
private static bool check(string filename)
{
string[] arr = new string[7] {"123", "456", "789", "1012", "1314", "1516", "1781"};
XmlDocument xml = new XmlDocument();
xml.Load(filename);
XmlNode x = xml.SelectSingleNode(@"/abc/def/efg/s");
string result = x.InnerText;
Console.WriteLine(result);
for (int i=0; i<arr[i].Length ;i++)
{
Console.WriteLine(arr[i] + " " + i);
if (arr[i] == result)
{ return true; }
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我得到一个例外:
System.IndexOutOfRangeException:索引超出了数组的边界.
现在,如果未找到匹配项,则会出现此异常.如果找到匹配则成功返回true.为什么它在返回false时给出异常:这是我如何从另一个方法调用该方法:
if (check(FileName))
{
// do something
}
Run Code Online (Sandbox Code Playgroud)
如果找不到匹配,请告知代码是否有错误.
我做了一个简单的窗体.我的按钮仅在第二次点击时触发.这是为什么 ?
private void button1_Click(object sender, EventArgs e)
{
//button1.Enabled = false; will disable the button before the event is fired
this.button1.Click += new System.EventHandler(this.dosomething);
}
private void dosomething(object sender, System.EventArgs e)
{
listBox1.Items.Add("Initializing :" + cart + "...");
this.button1.Click -= new System.EventHandler(this.dosomething);
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下.
是否可以使用 xslt 将文本文件转换为 xml。我知道我们可以从 xml 到文本,就像我之前所做的那样。但是我们有一个文本文件,需要使用 xslt 将其构造为 xml
这可能吗
更新:(下面是我需要解析为 xml 的文本文件)
C0707:00addd abcde
C0707:00tdef ghidd
C0715:00abcd fghi
Run Code Online (Sandbox Code Playgroud)
XML:
<b1>
<time>0707</time>
<text>addd</text>
<text2>abcde</text2>
<text>tdef</text>
<text2>ghid</text2>
</b1>
<b1>
<time>0715</time>
<text>abcd</text>
<text2>fghi</text2>
</b1>
Run Code Online (Sandbox Code Playgroud) 以下是sybase代码.有人可以看到以下是否正确.我想我错过了某处的语法
declare @test varchar(32)
select @test="/data/dump/team/"
update link
set link.value=
case when @test=substring(link.value,1,17)
then @test
when @test != substring(link.value,1,17)
value
end
where link.value != ""
and link_id=0 and row_id = 462135
Run Code Online (Sandbox Code Playgroud)
因为它给我以下错误:"第10行关键字结束附近的语法不正确".
可以请有人帮我解决语法问题.
我需要检查字符串中的值是否来自文件,是否更接近系统时间.我不想检查它是否等于.在系统时间范围内,该值应为+5或-5分钟.
e.g. If value from file is : 060700, and system time is 060500 OR 060900
I want to return a true
Run Code Online (Sandbox Code Playgroud)
我可以将文件时解析为:
DateTime filTime = DateTime.ParseExact(time, "HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture);
Run Code Online (Sandbox Code Playgroud)
然后获取当前系统时间:
DateTime curTime = DateTime.Now;
Run Code Online (Sandbox Code Playgroud)
但是现在应该如何检查+5或-5分钟范围.请指教.
我需要从xml中选择属性.这是xml:
<?xml version="1.0" encoding="utf-8"?>
<Examine>
<Categories>
<name text="test"/>
<name test="test2"/>
<name text="test3"/>
<name text="test4"/>
</Categories>
</Examine>
Run Code Online (Sandbox Code Playgroud)
这是代码,在以下帖子的帮助下:无法隐式转换类型system.colllections.generic
public class XmlValue
{
public System.Xml.Linq.XElement Element { get; set; }
public string Text
{
get
{
if (Element == null) return null;
return Element.Value;
}
}
}
public class XmlParser
{
public List<XmlValue> Getxml()
{
XDocument xdoc = XDocument.Load(@"D:\Web Utf-8 Converter\Categories.xml");
var list = xdoc.Descendants("Categories").SelectMany(p => p.Elements("name")).Select(e => new XmlValue {Element = e}).ToList();
var listing = list.ToList();
return listing;
}
} …Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×5
xml ×4
arrays ×1
ascii ×1
case ×1
code-signing ×1
file ×1
ioexception ×1
linq ×1
powershell ×1
sql ×1
sql-update ×1
time ×1
winforms ×1
xslt ×1