小编Ube*_*tor的帖子

Web Service API 提供多个要下载/保存的 csv 文件

我有一个网络服务,我可以调用并保存返回的 csv 文件。一切似乎都正常。我现在感兴趣的是返回多个 CSV 文件供用户下载。处理这个问题的正确方法是什么?我猜我需要一种方法来打包它们(zip?也许)?

[HttpPost]
[Route("OutputTemplate")]
public HttpResponseMessage OutputTemplate()
{
    HttpResponseMessage msg = new HttpResponseMessage();
    string body = this.Request.Content.ReadAsStringAsync().Result;
    try
    {
        string contents = DoStuff(body) // get contents based on body

        MemoryStream stream = new MemoryStream();
        StreamWriter writer = new StreamWriter(stream);
        writer.Write(contents);
        writer.Flush();
        stream.Position = 0;

        msg.StatusCode = HttpStatusCode.OK;
        msg.Content = new StreamContent(stream);
        msg.Content.Headers.ContentType = new MediaTypeHeaderValue("text/csv");
        msg.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = "fileexport"
            };

        return msg;

        }
        ...
    }
Run Code Online (Sandbox Code Playgroud)

c# asp.net

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

从X509Certificate2获取私钥时获取异常"指定的提供程序类型无效"或"密钥不存在"

尝试从X509Certificate2证书获取私钥时,我收到以下异常之一:

System.Security.Cryptography.CryptographicException:指定了无效的提供程序类型.

要么

System.Security.Cryptography.CryptographicException:以下代码行中不存在键:RSACryptoServiceProvider rsaKey =(RSACryptoServiceProvider)digiSignCert.PrivateKey;

堆栈跟踪:

System.Security.Cryptography.CryptographicException:键不存在.在System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType关键字类型,CspParameters参数,布尔randomKeyContainer,的Int32 dwKeySize,SafeProvHandle&safeProvHandle,SafeKeyHandle&safeKeyHandle)在System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()在System.Security.Cryptography.RSACryptoServiceProvider.位于Api.CertificateUtil.GetSignedXml(String xml,X509Certificate2 privateCert)的System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()中的.ctor(Int32 dwKeySize,CspParameters参数,布尔值useDefaultKeySize)

码:

public static RSACryptoServiceProvider rsaKey = null;
public X509Certificate2 _PrivateCert;

public APISearch()
{
    byte[] privateCert = null;//We get the actual certificate file data here
    GetPrivateCerificate(privateCert, "abc@123");
    GetSignedXml(_PrivateCert);
}

public void GetPrivateCerificate(byte[] privateCert, string pwd)
{
    _PrivateCert = new X509Certificate2(privateCert, pwd, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
}

public void GetSignedXml(X509Certificate2 privateCert)
{
    rsaKey = (RSACryptoServiceProvider)privateCert.PrivateKey; //Occassional Exception
}
Run Code Online (Sandbox Code Playgroud)

预期结果:(RSACryptoServiceProvider)privateCert.PrivateKey应始终生成私钥.

实际结果:有时上述异常会抛出此行:

rsaKey = (RSACryptoServiceProvider)privateCert.PrivateKey;

有时,从证书文件中成功获取私钥.截至目前,我们无法跟踪此问题的模式.

c# cryptography rsacryptoserviceprovider x509certificate2 x509certificate

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

For循环中的日期时间

我在日期时间有一个for循环,怎么counter不增加.我没有看到原因.你能帮我吗?

private void ubGO_Click(object sender, EventArgs e)
{
    DateTime startDate = udteMin.DateTime.Date;
    DateTime endDate = udteMax.DateTime.Date;

    for (DateTime counter = startDate; counter <= endDate; counter.AddDays(1))
    {
        MessageBox.Show(counter.Date.ToString() + "            " + counter.AddDays(1).Date.ToString());
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# winforms

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

使用 C# 以编程方式在 Word 2010 加载项中查找和填充书签

我在 Visual Studio 中有一个 Microsoft Word 2010 插件项目,我只是按照 MSDN 指南在功能区上制作了一个具有自定义功能的新选项卡。我已经进行了一些谷歌搜索,但我似乎找不到任何示例(或者如果可能的话)使用 C# 查找书签,然后在 SQL 查询中使用书签名称并填充它。我正在处理的文档可能有几十个书签,并且有数百个文档。自动化这一过程是当务之急。

c# ms-word visual-studio-2013

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

C#SQL数据到标签控件?

谁能告诉我为什么这不起作用?我没有在代码中收到错误,但信息(月,日)没有显示在标签中.连接处于活动状态,数据存在.它只是不会显示.

列表框(listNames)从数据库中填充,并且工作正常.我想要的是从列表框中选择的记录中的MONTH和DAY信息显示为标签.

谢谢你的帮助.

private void listNames_SelectedIndexChanged(object sender, EventArgs e)
{
    using (connection = new SqlConnection(connectionString))
    using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM members WHERE Name = " + listNames.SelectedItem.ToString(), connection))
    {
        DataTable showlistTable = new DataTable();
        DataSet info = new DataSet();
        adapter.Fill(showlistTable);
        adapter.Fill(info);

        labelDetailsMonth.Text = info.Tables[0].Rows[0]["Month"].ToString();
        labelDetailsDay.Text = info.Tables[0].Rows[0]["Day"].ToString();
    }
}
Run Code Online (Sandbox Code Playgroud)

c# sql

0
推荐指数
1
解决办法
73
查看次数