小编Abh*_*hek的帖子

服务器提交了协议违规.Section = ResponseHeader Detail = CR必须后跟LF,在WinForms中?

我试图使用WebClient/HttpWebRequest从服务器下载一些数据.我使用以下代码来执行此操作:

WebClient client = new WebClient();
client.Credentials = new NetworkCredential("admin", "password");
Stream datastream = client.OpenRead("http://routerlogin.com/cgi-bin/CF_logs.html");
StreamReader reader = new StreamReader(datastream);
Run Code Online (Sandbox Code Playgroud)

服务器是我的页面在路由器的配置中.它可以在浏览器中正常工作,但是当使用我的代码下载时,它会抛出一条WebException消息

服务器提交了协议违规.Section = ResponseHeader Detail = CR必须后跟LF,在WinForms?中.

我找到了一个解决方案,如果他们使用ASP.net,可以使用,将以下内容添加到web.config:

<configuration> 
    <system.net> 
        <settings> 
            <httpWebRequest useUnsafeHeaderParsing="true" /> 
        </settings> 
    </system.net> 
</configuration>
Run Code Online (Sandbox Code Playgroud)

但是,我正在制作一个WinForms应用程序,所以这对我不起作用.有什么替代方法可以解决这个问题?

c# webclient httpwebrequest system.net.webexception winforms

40
推荐指数
1
解决办法
5万
查看次数

Winforms c# - 将焦点设置为TabPage的第一个子控件

说我有一个Textbox嵌套在一个TabControl.

当表单加载时,我想关注它Textbox(默认情况下焦点设置为TabControl).

只是textbox1.focus()Load表单的情况下调用似乎不起作用.

我已经能够通过执行以下操作来关注它:

 private void frmMainLoad(object sender, EventArgs e)
 {
     foreach (TabPage tab in this.tabControl1.TabPages) 
     {
         this.tabControl1.SelectedTab = tab;
     }
 }
Run Code Online (Sandbox Code Playgroud)

我的问题是:

有没有更优雅的方式来做到这一点?

.net c# focus winforms

20
推荐指数
2
解决办法
4万
查看次数

Windows.Form没有激活keyDown事件

private void screensaverWindow_Load(object sender, System.EventArgs e)
{            
    this.BringToFront();            
    this.Focus();
    this.KeyPreview = true;
    this.KeyDown += new KeyEventHandler(onkeyDown);            
}        
Run Code Online (Sandbox Code Playgroud)

onKeyDown()永远不会被称为.知道为什么吗?

编辑:这在发布模式下工作!?我想它必须是视觉工作室调试器干扰某处

c# input winforms

16
推荐指数
2
解决办法
3万
查看次数

将Excel文件从.csv转换为.xlsx

我希望我的应用程序去找一个 excel文件并将其转换为.xlsx文件.

这就是我目前正在做的事情;

var fileName = @"Z:\0328\orders\PurchaseOrder.csv";
FileInfo f = new FileInfo(fileName);
f.MoveTo(Path.ChangeExtension(fileName, ".xlsx"));
var Newfile = @"Z:\0328\orders\PurchaseOrder.xlsx";
Run Code Online (Sandbox Code Playgroud)

现在这确实有效.它将文件扩展名更改为我想要的格式.然而,该文件然后变得"腐败"或至少Excel拒绝打开它,当我尝试进一步冒险时我的应用程序也不会.

有没有人有解决方案/解决方案?

c# winforms

15
推荐指数
3
解决办法
6万
查看次数

如何从GridView中删除一行?

我正在使用 2005 GridView控件.

如何从中删除特定行GridView.

我写了以下代码.但它不起作用......

DataRow dr = dtPrf_Mstr.NewRow();
dtPrf_Mstr.Rows.Add(dr);
GVGLCode.DataSource = dtPrf_Mstr;
GVGLCode.DataBind();

int iCount = GVGLCode.Rows.Count;
for (int i = 0; i <= iCount; i++)
{
    GVGLCode.DeleteRow(i);
}
GVGLCode.DataBind();
Run Code Online (Sandbox Code Playgroud)

c# asp.net gridview delete-row

10
推荐指数
2
解决办法
14万
查看次数

如何从XML文档中读取值以构建ComboBox?

我正在尝试读取我想为妈妈制作的文件.基本上这就是我想做的事情:

  1. A ComboBox将显示XML中的所有蔬菜名称.
  2. 选择蔬菜后,第二个ComboBox将显示XML中的食谱名称,该名称可以使用在第一个菜单中选择的蔬菜ComboBox进行烹饪.
  3. 最后,通过OK Button,所选配方将读取通向配方的文件路径.

我写的XML

<Vegetables>
    <vegetable name="Carrot">
        <recipe name="ABCrecipe">
            <FilePath>C:\\</FilePath>
        </recipe>
        <recipe name="DEFrecipe">
            <FilePath>D:\\</FilePath>
        </recipe>   
    </vegetable>
    <vegetable name="Potato">
        <recipe name="CBArecipe">
            <FilePath>E:\\</FilePath>
        </recipe>
            <recipe name"FEDrecipe">
            <FilePath>F:\\</FilePath>
        </recipe>
    </vegetable>
</Vegetables>
Run Code Online (Sandbox Code Playgroud)

C#代码

private void Form1_Load(object sender, EventArgs e)
{
    XmlDocument xDoc = new XmlDocument();
    xDoc.Load("Recipe_List.xml");
    XmlNodeList vegetables = xDoc.GetElementsByTagName("Vegetable");
    for (int i = 0; i < vegetables.Count; i++)
    {
        comboBox1.Items.Add(vegetables[i].Attributes["name"].InnerText);
    }
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    //I'm lost at …
Run Code Online (Sandbox Code Playgroud)

c# xml winforms

6
推荐指数
1
解决办法
5275
查看次数

java.lang.NoClassDefFoundError:io / restassured / mapper / factory / GsonObjectMapperFactory

当我尝试使用放心的框架执行脚本时出现错误。请指导我解决相同的问题。我用下面的罐子

Java版本-8 rest-assured-2.8.0 json-path-2.8.0 hamcrest-all-1.3 commons-lang3-3.0 json-schema-validator-2.2.0

失败:foo java.lang.NoClassDefFoundError:io / restassured / mapper / factory / GsonObjectMapperFactory at io.restassured.config.RestAssuredConfig。(RestAssuredConfig.java:41)at io.restassured.RestAssured。(RestAssured.java:420)在实践中.java的sun.reflect.NativeMethodAccessorImpl.invoke.getRequest.foo(GetRequest.java:12)in sun.reflect.DelegatingMethodAccessorImpl.invoke(未知方法)处sun.reflect.NativeMethodAccessorImpl.invoke(未知方法)java。 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)位于org.testng.internal.Invoker.invokeMethod(Invoker.java:661)处的lang.reflect.Method.invoke(未知源)。内部的Internal.Invoker.invokeTestMethod(Invoker.java:869)。org上org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)的org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)org的org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)位于org.testng.SuiteRunner.runTest(SuiteRunner.java:380)的org.testng.TestRunner.run(TestRunner.java:602)的org.testng.SuiteRunner.runTest(SuiteRunner.java:380)的org.testng.SuiteRunner的.testng.TestRunner.privateRun(TestRunner.java:744)在org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)在org.testng.SuiteRunner.run(SuiteRunner.java:289)在org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java)上运行(SuiteRunner.java:375) :52),位于org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)at org.testng.TestNG.runSuitesLocal(TestNG.java:1226)at org.testng.TestNG.runSuites(TestNG.java:1144)at org.testng.TestNG.run(TestNG.java:1115)at org。在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)处的testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)引起:java.lang.ClassNotFoundException:io.restassured.mapper.factory.GsonObjectMapperFactory在java.net.URLClassLoader.findClass(未知源)在java.lang.ClassLoader.loadClass(未知源)在sun.misc.Launcher $ AppClassLoader.loadClass java.lang.ClassLoader.loadClass中的(未知源)(未知源)...更多281226)at org.testng.TestNG.runSuites(TestNG.java:1144)at org.testng.TestNG.run(TestNG.java:1115)at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)位于org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)由以下原因引起:java.lang.ClassNotFoundException:io.restassured.mapper.factory。 GsonObjectMapperFactory,位于java.net.URLClassLoader.findClass(未知源),位于java.lang.ClassLoader.loadClass(未知源),位于sun.misc.Launcher $ AppClassLoader.loadClass(未知源),位于java.lang.ClassLoader.loadClass(未知源) )...另外28个1226)at org.testng.TestNG.runSuites(TestNG.java:1144)at org.testng.TestNG.run(TestNG.java:1115)at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)位于org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)由以下原因引起:java.lang.ClassNotFoundException:io.restassured.mapper.factory。 GsonObjectMapperFactory,位于java.net.URLClassLoader.findClass(未知源),位于java.lang.ClassLoader.loadClass(未知源),位于sun.misc.Launcher $ AppClassLoader.loadClass(未知源),位于java.lang.ClassLoader.loadClass(未知源) )...另外28个1115)在org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java :76)由以下原因引起:java.lang.ClassNotFoundException:io.restassured.mapper.factory.GsonObjectMapperFactory在java.net.URLClassLoader.findClass(未知源)在java.lang.ClassLoader.loadClass(未知源)在sun.misc。 java.lang.ClassLoader.loadClass(未知源)的Launcher $ AppClassLoader.loadClass(未知源)...更多281115)在org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java :76)由以下原因引起:java.lang.ClassNotFoundException:io.restassured.mapper.factory.GsonObjectMapperFactory在java.net.URLClassLoader.findClass(未知源)在java.lang.ClassLoader.loadClass(未知源)在sun.misc。 java.lang.ClassLoader.loadClass(未知源)的Launcher $ AppClassLoader.loadClass(未知源)...更多2876)由以下原因引起:java.lang.ClassNotFoundException:io.restassured.mapper.factory.GsonObjectMapperFactory在java.net.URLClassLoader.findClass(Unknown Source)在java.lang.ClassLoader.loadClass(Unknown Source)在sun.misc.Launcher java.lang.ClassLoader.loadClass的$ AppClassLoader.loadClass(未知源)... 28更多76)由以下原因引起:java.lang.ClassNotFoundException:io.restassured.mapper.factory.GsonObjectMapperFactory在java.net.URLClassLoader.findClass(Unknown Source)在java.lang.ClassLoader.loadClass(Unknown Source)在sun.misc.Launcher java.lang.ClassLoader.loadClass的$ AppClassLoader.loadClass(未知源)... 28更多

===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests …
Run Code Online (Sandbox Code Playgroud)

rest-assured

6
推荐指数
4
解决办法
7966
查看次数

.NET 应用程序中 Python 代码的编辑器

我有一个 WinForms 应用程序。应用程序的要求之一是运行 Python 脚本。为此,我正在使用IronPython. 我可以要求用户保存 Python 脚本文件,然后从其位置执行脚本。

但是,如果我可以为 Python 脚本提供具有语法突出显示和自动完成功能的应用程序内编辑器,那么对用户来说会更好也更容易。

Notepad++ 对于编写 Python 代码非常有用。但它不能通过我的 C# 代码进行配置。

AvalonEdit用于 WPF,我的应用程序是 WinForms。我注意到 IronLab 没有自动完成功能。

提供此类功能的最佳选择是什么?

c# python ironpython winforms

5
推荐指数
0
解决办法
1060
查看次数

C#CheckedListBox多列

我在C#中有一个checkboxlist控件。

我想知道谁在其中添加多列。multicolumn属性设置为true。我只想知道添加2列的编码。

我的代码是

while (true)
{
    data = SDK.GetNext("ACCHISTL", 6);
    document_details = data.Split('|');
    if (document_details[0] == "0")
    {
        if (document_details[3] == Document_nr)
        {
            lbLines.Items.su(document_details[4] + " -> " + document_details[14],true);
        }
        else
        {
            break;
        }
    }
    else
    {
        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

您能帮我示范正确的方法吗?

c# checkbox multiple-columns winforms

5
推荐指数
1
解决办法
1万
查看次数

MVC预览4 - 路由表中的路由与提供的值不匹配

我有一个我通过RedirectToRoute调用的路由,如下所示:

return this.RedirectToRoute("Super-SuperRoute", new { year = selectedYear });
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

 return this.RedirectToRoute("Super-SuperRoute", new { controller = "Super", action = "SuperRoute", id = "RouteTopic", year = selectedYear });
Run Code Online (Sandbox Code Playgroud)

global.asax中的路由是这样的:

routes.MapRoute(
    "Super-SuperRoute", // Route name
    "Super.mvc/SuperRoute/{year}",  // URL with parameters
     new { controller = "Super", action = "SuperRoute", id = "RouteTopic" }  // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud)

那么为什么我会收到错误:"路由表中没有路由与提供的值匹配."?

我看到selectedYear的类型是var.当我尝试使用int.Parse转换为int时,我意识到selectedYear实际上是null,这可以解释问题.我想下次我会更加注意断点处变量的值:)

asp.net-mvc asp.net-mvc-routing

4
推荐指数
1
解决办法
2909
查看次数