首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ConvertApi NuGet包错误:无法安装包'ConvertApi 2.7.0‘

ConvertApi NuGet包错误:无法安装包'ConvertApi 2.7.0‘
EN

Stack Overflow用户
提问于 2019-07-09 21:29:25
回答 1查看 88关注 0票数 1

我正在添加package包来将ConvertApi转换为Doc文件,但得到以下错误

无法安装程序包'ConvertApi 2.7.0‘。您正在尝试将此包安装到目标为'.NETFramework,Version=v4.6.1‘的项目中,但该包不包含任何与该框架兼容的程序集引用或内容文件。

注意:您也可以建议使用其他一些API来完成上述任务。

EN

回答 1

Stack Overflow用户

发布于 2019-07-22 16:56:53

ConvertApi 2.7.0 NuGet包是.NET Core 2版本库,可以安装在.NET 4.7 or higher上。但是,您可以使用普通的C#实现来调用ConvertAPI REST API,下面的示例使用WebClient发送一个MS Word文件以转换为PDF文档。

代码语言:javascript
复制
using System;
using System.Net;
using System.IO;

class MainClass {
  public static void Main (string[] args) {
            const string fileToConvert = "test.docx";
            const string fileToSave = "test.pdf";           
            const string Secret="";

            if (string.IsNullOrEmpty(Secret))
              Console.WriteLine("The secret is missing, get one for free at https://www.convertapi.com/a");
            else
              try
              {
                  Console.WriteLine("Please wait, converting!");
                  using (var client = new WebClient())
                  {
                      client.Headers.Add("accept", "application/octet-stream");
                      var resultFile = client.UploadFile(new Uri("http://v2.convertapi.com/convert/docx/to/pdf?Secret=" + Secret), fileToConvert); 
                      File.WriteAllBytes(fileToSave, resultFile );
                      Console.WriteLine("File converted successfully");
                  }
              }
              catch (WebException e)
              {
                  Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode);
                  Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription);
                  Console.WriteLine("Body : {0}", new StreamReader(e.Response.GetResponseStream()).ReadToEnd());
              }
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56953744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档