小编ahm*_*iee的帖子

使用C#下载Windows更新

有没有办法从C#应用程序中以编程方式下载Windows更新?我想在我的应用程序中管理更新的安装.

c# windows windows-update c#-4.0

8
推荐指数
1
解决办法
2632
查看次数

淡化面板 - Windows窗体

我有一个可以显示或隐藏的详细信息面板.

如何显示/隐藏该面板(当然还有其内容)的简单淡入淡出效果?

我正在使用Windows窗体,并且控件opacity在Windows窗体中没有属性.

c# .net-3.5 winforms

8
推荐指数
1
解决办法
9070
查看次数

如何获取网址的内容类型?

我想获得一个网址类型.例如是一个HTML页面,其页面类型text/html,但类型text/xml.这个页面的类型似乎是,image/png但它是text/html.

我想知道我怎么可以检测如Web地址的内容类型

.net c# content-type c#-4.0

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

如何将web api用作Web服务?

我已经创建了一个测试ASP.Net Web Api,现在我想知道如何在Windows窗体应用程序中将它用作Web服务?

当前URL是http://localhost:59682,当我添加http://localhost:59682http://localhost:59682/api/http://localhost:59682/api/products/作为网络服务参考我得到这个错误:There was an error downloading 'http://localhost:59682/api/products/$metadata'. The request failed with HTTP status 400: Bad Request. Metadata contains a reference that cannot be resolved: 'http://localhost:59682/api/products/'. The remote server returned an unexpected response: (405) Method Not Allowed. The remote server returned an error: (405) Method Not Allowed. If the service is defined in the current solution, try building the solution and adding the service reference again.

这是我的web.config:

<?xml version="1.0" encoding="utf-8"?> …
Run Code Online (Sandbox Code Playgroud)

c# asp.net web-services c#-4.0 asp.net-web-api

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

当文件位于必须的位置时,ClickOnce无法找到其先决条件

我想使用具有一些先决条件的ClickOnce发布我的应用程序(.NET 4.5和SQL Server Express).

我按照如何:在ClickOnce应用程序中包含先决条件(请注意包文件夹位于v8.1A文件夹而不是v8A文件夹)中进行了操作,但仍然说它无法找到文件.我已经尝试过Visual Studio 2013Visual Studio 2015 RC.

要在"先决条件"对话框中启用"从我的应用程序的相同位置下载先决条件",必须将项目"Microsoft .NET Framework 4.5(x86和x64)"的文件"DotNetFX45\dotNetFx45_Full_x86_x64.exe"下载到本地计算机.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=239883.

要在"先决条件"对话框中启用"从我的应用程序的相同位置下载先决条件",必须将项目"SQL Server 2012 Express"的文件"SqlExpress2012\SQLEXPR32_x86_ENU.EXE"下载到本地计算机.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=239883.

要在"先决条件"对话框中启用"从我的应用程序的相同位置下载先决条件",必须将项目"SQL Server 2012 Express"的文件"SqlExpress2012\SQLEXPR_x64_ENU.EXE"下载到本地计算机.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=239883.

要在"先决条件"对话框中启用"从我的应用程序的相同位置下载先决条件",必须为项目"Microsoft .NET Framework 4 Client Profile(x86和x64)和.NET for Update"下载文件"DotNetFX40ClientKB2468871\dotNetFx40_Client_x86_x64.exe".框架4(KB2468871)'到您的本地机器.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=239883.

.net c# clickonce visual-studio

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

为什么HTML Agility Pack HtmlDocument.DocumentNode为空?

我正在使用此代码来更改HTML流的href属性.

首先我使用以下代码下载完整的html页面:( URL是网页地址)

HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(URL);
HttpWebResponse myHttpWebResponse = 
                         (HttpWebResponse)myHttpWebRequest.GetResponse();

Stream s = myHttpWebResponse.GetResponseStream();
Run Code Online (Sandbox Code Playgroud)

然后我处理这个:

HtmlDocument doc = new HtmlDocument();

doc.Load(s);
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("/a"))
{
    string att = link.Attributes["href"].Value;
    link.Attributes["href"].Value = "http://ahmadalli.somee.com/default.aspx?url=" + att;
}
doc.Save(s);
Run Code Online (Sandbox Code Playgroud)

s 是HTML流.

但我有一个例外,说doc.DocumentNode是空的!

我试过很多网站,但是doc.DocumentNode没有

c# asp.net html-agility-pack

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

使用Stream显示Image*.ico

我想用扩展名显示图像,*.ico我用Stream它来做.但我有一个问题.

随着扩展*.jpg,*.bmp...图像显示确定,但*.ico它没有显示

这是我的代码:

 private void OutputStream(string fileName)
    {
        try
        {
            Stream dataStream = null;

                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPFile spFile = web.GetFile(fileName);
                    dataStream = spFile.OpenBinaryStream();
                    this.HandleOutputStream(dataStream);
                });

        }
        catch (System.Threading.ThreadAbortException exTemp)
        {
            logger.Error("KBStreamPicture::OutputStream", exTemp);
        }
        catch (Exception ex)
        {
            //System.Diagnostics.Debug.Write("OutputStream::" + ex);
            logger.Error("KBStreamPicture::OutputStream", ex);
        }
    }
Run Code Online (Sandbox Code Playgroud)

private void HandleOutputStream(Stream dataStream)
    {
        const int bufferSize = 16384; //16KB 

        using (Stream file = dataStream)
        {
            if (file != null)
            {
                this.Page.Response.Clear();
                this.Page.Response.Cache.SetCacheability(System.Web.HttpCacheability.Private);
                this.Page.Response.Cache.SetExpires(DateTime.Now.AddMinutes(20)); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net stream

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

如何在当前标签之后打开新标签?

我正在开发一个chrome扩展程序,我想打开一个新选项卡,但是在用户所在的当前选项卡之后.这就是我试图做的事情:

function clickEvent(info, tab) {
    update();
    var url= "http://google.com";
    var id = tab.id+1;
    chrome.tabs.create({'url': url, 'index': id});
}
Run Code Online (Sandbox Code Playgroud)

但是创建的选项卡会在chrome选项卡栏中的选项卡队列末尾打开.'index': id从中删除后chrome.tabs.create,结果是一样的.我不知道如何解决问题.有谁能够帮我?

google-chrome google-chrome-extension

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

MiniProfiler不起作用

我刚刚创建了一个新的MVC 4 Basic项目,并将该软件包添加到项目中,并将所需的代码添加到布局中,但在首次运行后没有任何反应.

这是布局:

@using StackExchange.Profiling;
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>
    @MiniProfiler.RenderIncludes()
    @RenderBody()

    @Scripts.Render("~/bundles/jquery")
    @RenderSection("scripts", required: false)
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

更新

我已将此代码添加到了 global.asax.cs

protected void Application_BeginRequest()
{

    MiniProfiler.Start();

}
Run Code Online (Sandbox Code Playgroud)

现在这段代码出现在HTML代码中:

<script async type="text/javascript" id="mini-profiler" src="/mini-profiler-resources/includes.js?v=xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=" data-version="xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=" data-path="/mini-profiler-resources/" data-current-id="6da0f73c-fa89-447b-92b1-56dc532947f4" data-ids="6da0f73c-fa89-447b-92b1-56dc532947f4" data-position="left" data-trivial="false" data-children="false" data-max-traces="15" data-controls="false" data-authorized="true" data-toggle-shortcut="Alt+P" data-start-hidden="false"></script>
Run Code Online (Sandbox Code Playgroud)

但是/mini-profiler-resources/includes.js?v=xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=url返回404错误.

c# asp.net asp.net-mvc asp.net-mvc-4 mvcminiprofiler

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

文件或文件夹重命名为小写在 C# 中使用 DirectoryInfo/FileInfo.MoveTo()

我有一个程序可以将文件或文件夹重命名为小写名称。我写了这段代码:

    private void Replace(string FolderLocation, string lastText, string NewText)
    {
        if (lastText == "")
        {
            lastText = " ";
        }
        if (NewText == "")
        {
            NewText = " ";
        }

        DirectoryInfo i = new DirectoryInfo(FolderLocation);
        string NewName = "";
        if (checkBox2.Checked)
        {
            if (i.Parent.FullName[i.Parent.FullName.Length - 1].ToString() != "\\") //For parents like E:/
            {
                NewName = i.Parent.FullName + "\\" + i.Name.Replace(lastText, NewText);
            }
            else
            {
                NewName = i.Parent.FullName + i.Name.Replace(lastText, NewText);
            }

                NewName = NewName.ToLower();


            if (NewName != i.FullName)
            {
                 i.MoveTo(NewName); …
Run Code Online (Sandbox Code Playgroud)

.net c# directoryinfo fileinfo file-rename

3
推荐指数
1
解决办法
7682
查看次数