指定的软件包无效。主要部分缺失 - c#

下面给出了一个合并功能,该功能旨在合并文件夹中的所有docx文件并生成合并的文件。

public  void Merge()
{  
    try
    {

        string sid = Request.QueryString["studid"];
        string stud = sid.ToString();

        string ds = HttpContext.Current.Server.MapPath(("~\\StudentBinder") + "\\Temp4\\");
        if (Directory.Exists(ds))
        {
            DirectoryInfo d = new DirectoryInfo(ds);
            FileInfo[] Files = d.GetFiles("*" + stud + "*.docx");

              // stud added for differentiating b/w users

            string[] filepaths = new string[Files.Length];
            int index = 0;

            foreach (FileInfo file in Files)
            {
                filepaths[index] = file.Name;
                index++;
            }


                using (WordprocessingDocument myDoc = WordprocessingDocument.Open(Server.MapPath(filepaths[0]), true))

                {
                    for (int i = 1; i < filepaths.Length; i++)
                    {
                        MainDocumentPart mainPart = myDoc.MainDocumentPart;
                        string altChunkId = "AltChunkId" + i.ToString();
                        AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML, altChunkId);
                        using (FileStream fileStream = File.Open(@filepaths[i], FileMode.Open))
                        {
                            chunk.FeedData(fileStream);
                        }
                        AltChunk altChunk = new AltChunk();
                        altChunk.Id = altChunkId;
                        mainPart.Document.Body.InsertAfter(altChunk, mainPart.Document.Body.Elements<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().Last());
                        mainPart.Document.Save();
                        myDoc.Close();
                    }
                }
        }
    }
    catch (Exception ex)
    {
    }
}

但是线

using (WordprocessingDocument myDoc = WordprocessingDocument.Open(Server.MapPath(filepaths[0]), true))

引发错误指定的包无效。主要部分丢失。

我不知道那句话出了什么问题。任何建议都欢迎。提前致谢。

参考方案

您可能两次执行Server.MapPath:

string ds = HttpContext.Current.Server.MapPath(("~\\StudentBinder")+"\\Temp4\\")

并在行中

using (WordprocessingDocument myDoc = WordprocessingDocument.Open(Server.MapPath(filepaths[0]), true))

您可以将此行重写为

using (WordprocessingDocument myDoc = WordprocessingDocument.Open(filepaths[0], true))

并且您还需要从file.FullName而不是file.Name填充filepaths数组:

foreach (FileInfo file in Files)
{
    filepaths[index] = file.FullName;
    index++;
}

ddl在服务器中未更新-asp.net - javascript

我在ASP.NET c#上工作。我有一个DropDownList。 (runat =“ server”)在$ {document).ready上,我更新了它的值:$(document).ready(function () { document.getElementById("ddl").value = "abc"; ……

ASP.NET-如何更改JSON序列化的方式? - javascript

我正在使用ASP.NET通过以下查询返回Json文件:public ActionResult getTransactionTotals(int itemID) { DBEntities db = new DBEntities(); var query = from trans in db.Transactions // Linq query removed …

ASP.NET MVC中应为DataTable返回哪种数据? - javascript

我想为DataTable中的每个页面创建动态加载信息。我正在尝试遵循以下示例:https://www.datatables.net/manual/server-sidehttps://www.datatables.net/manual/data来自示例的代码:$('#example').DataTable( { serverSide: t…

Asp.Net:在服务器端还原DropDownList的客户端SelectedItem - c#

因此,我的页面上有一个dropDownList,其中包含数百个项目。用户可以通过在文本框中键入一些文本来过滤此DDL。然后对DDL进行相应的过滤(所有不包含输入文本的项目都将通过JavaScript删除)。然后,用户选择他的项目并按下按钮。通常,这将导致错误,因为DDL已更改并且ASP验证了PostBack数据。但是,使用EnableEventValidat…

asp.net mvc中的对象数组数据始终为null - javascript

我需要通过json将对象数组发送到asp.net mvc 2,但是我在mvc控制器中没有得到null对象是这样的entries[1].date = "12/22/2014" entries[1].Ref = "0002" entries[1].Credit = "100" entries[2].da…