简体   繁体   English

CS0012 C#类型“ HttpContext”在未引用的程序集中定义

[英]CS0012 C# The type 'HttpContext' is defined in an assembly that is not referenced

I have this code to Merge documents to .PDF using Spire but i get the following code in this line result.Save(outputFile,Spire.Pdf.FileFormat.PDF); 我有这段代码可以使用Spire将文档合并到.PDF中,但是我在此行结果中得到以下代码result.Save(outputFile,Spire.Pdf.FileFormat.PDF);

CS0012 C# The type 'HttpContext' is defined in an assembly that is not referenced. CS0012 C#类型'HttpContext'在未引用的程序集中定义。 You must add a reference to assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 您必须添加对程序集'System.Web,版本= 4.0.0.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a'的引用。

I tried to add this Assembly code to App.config file but no luck. 我试图将此Assembly代码添加到App.config文件中,但是没有运气。

<assemblies>
        <add assembly="MyAssembly" Version="4.0.0.0" Culture="neutral" PublicKeyToken="b03f5f7f11d50a3a"/>   

Here is the code below 这是下面的代码

private void button1_Click(object sender, EventArgs e)
        {

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "All files (*.docx, *.pdf, *.pptx, *.pdf)| *.docx; *.pdf; *.pptx; *.xlsx";

            ofd.Multiselect = true;

            if (DialogResult.OK == ofd.ShowDialog())
            {

                string[] files = ofd.FileNames;

                listBox1.Items.AddRange(files);
            }

    }

        private void button2_Click(object sender, EventArgs e)
        {
            string ext = string.Empty;
            List<Stream> filesStreams = new List<Stream>();
            MemoryStream ms1 = new MemoryStream();
            MemoryStream ms2 = new MemoryStream();
            MemoryStream ms3 = new MemoryStream();
            foreach (object item in listBox1.Items)
            {
                ext = Path.GetExtension(item.ToString());
                switch (ext)
                {
                    case ".docx":
                        Document doc = new Document(item.ToString());
                        doc.SaveToStream(ms1, Spire.Doc.FileFormat.PDF);
                        filesStreams.Add(ms1);

                        break;
                    case ".pdf":
                        filesStreams.Add(File.OpenRead(item.ToString()));
                        break;
                    case ".pptx":
                        Presentation ppt = new Presentation(item.ToString(), Spire.Presentation.FileFormat.Auto);
                        ppt.SaveToFile(ms2, Spire.Presentation.FileFormat.PDF);
                        filesStreams.Add(ms2);

                        break;
                    case ".xlsx":
                        Workbook xls = new Workbook();
                        xls.LoadFromFile(item.ToString());
                        xls.SaveToStream(ms3, Spire.Xls.FileFormat.PDF);
                        filesStreams.Add(ms3);

                        break;
                    default:
                        break;

                }
            }
            string outputFile = "result.doc";
            PdfDocumentBase result = PdfDocument.MergeFiles(filesStreams.ToArray());
            //result.SaveToDoc(outputFile);
            result.Save(outputFile,Spire.Pdf.FileFormat.PDF);
            ms1.Close();
            ms2.Close();
            ms3.Close();

    }

Thank you 谢谢

Add reference of System.Web library by right clicking the project in Solution Explorer window and then clicking Add Reference option from the context menu. 右键单击“解决方案资源管理器”窗口中的项目,然后从上下文菜单中单击“添加引用”选项,以添加System.Web库的引用。

The above action will open up the Add Reference Dialog and from the .Net Tab, you need to choose System.Web library and click OK. 上面的操作将打开“添加引用”对话框,并从.Net选项卡中,您需要选择System.Web库,然后单击“确定”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CS0012 类型“EventLogEntryType”在未引用的程序集中定义 - CS0012 The type 'EventLogEntryType' is defined in an assembly that is not referenced 错误CS0012:类型“DbConnection”在未引用的程序集中定义 - Error CS0012: The type 'DbConnection' is defined in an assembly that is not referenced 错误CS0012:类型'TaskAwaiter <>'在未引用的程序集中定义 - error CS0012: The type 'TaskAwaiter<>' is defined in an assembly that is not referenced .Net Core-CS0012&#39;对象&#39;在未引用的程序集中定义 - .Net Core - CS0012 'Object' is defined in an assembly that is not referenced 错误CS0012:类型&#39;ConnectionStringSettings&#39;在升级到Visual Studio 2015后未引用的程序集中定义 - error CS0012: The type 'ConnectionStringSettings' is defined in an assembly that is not referenced after upgrading to Visual Studio 2015 使用RazorTemplates库时发生错误:&#39;CS0012:类型&#39;System.Attribute&#39;在未引用的程序集中定义&#39; - Error when using RazorTemplates library: 'CS0012: The type 'System.Attribute' is defined in an assembly that is not referenced' CS0012 System.enum在未针对.NET 4.5的构建服务器上引用的程序集中定义 - CS0012 System.enum is defined in an assembly not referenced on build server targeting .NET 4.5 使用C#代码生成问题-CS0012-IsLongModifier - Build issue with c# code - CS0012 - IsLongModifier 带有显式调用的 C# 构造函数歧义 - 错误 CS0012 - C# Constructors Ambiguity with explicit call - Error CS0012 MSBuild错误CS0012 - MSBuild Error CS0012
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM