itextsharp进程无法访问该文件

时间:2012-10-06 03:12:30

标签: itextsharp

我需要一些认真的帮助。我遇到了麻烦,我很感激能得到的任何帮助。我在网上搜了几个小时,我空手而归。我创建了一个在目录中进行递归并将所有图像转换为PDF的项目。我正在使用itextsharp和pdfsharp(他们似乎没有彼此工作得很好)。无论如何,这个项目工作得很完美,直到视觉工作室抱怨组件,我从上一次学习VS修复它破坏它们的东西。所以,我忽略了它。虽然在手机上插入[插入多彩的单词] beta测试它,但他混淆了我的地狱,我最后点击了VS投掷的警告。当我点击它时,我开始出现以下错误:1)转换pdf文件时,它只转换目录中任何文件的前15个字节。 2)当PDF已经存在时,它会在标题中出现异常。以下是我正在使用的代码,它完美地工作:

WebException未处理(这不是WEB APP ) 该进程无法访问文件'filepath \ andname.pdf',因为它正由另一个进程使用。

在此之前,当我在我的应用程序的app.config部分加载原始代码时,我会收到此错误:

FileLoadException未处理 无法加载文件或程序集'itextsharp,Version = 5.3.2.0,Culture = neutral,PublicKeyToken = 8354ae6d2174ddca'或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040)

任何人都可以请在我扼杀这个家伙并在黑市上卖掉他的肝脏之前请帮助我吗?这真令人沮丧。我将不胜感激。

./的x86

按照标题中的方式触发访问的app.config文件,并且只向应用程序添加15个字节:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="TAMI.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <system.diagnostics>
  </system.diagnostics>
  <userSettings>
    <TAMI.My.MySettings>
      <setting name="scanner" serializeAs="String">
        <value />
      </setting>
      <setting name="authenticated_user" serializeAs="String">
        <value />
      </setting>
    </TAMI.My.MySettings>
  </userSettings>
</configuration>

错误与错误版本错误的组合

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="TAMI.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
    </sectionGroup>
  </configSections>
  <system.diagnostics>
    <sources>
      <!-- This section defines the logging configuration for My.Application.Log -->
      <source name="DefaultSource" switchName="DefaultSwitch">
        <listeners>
          <add name="FileLog"/>
          <!-- Uncomment the below section to write to the Application Event Log -->
          <!--<add name="EventLog"/>-->
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="DefaultSwitch" value="Information"/>
    </switches>
    <sharedListeners>
      <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/>
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
      <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
    </sharedListeners>
  </system.diagnostics>
  <userSettings>
    <TAMI.My.MySettings>
      <setting name="scanner" serializeAs="String">
        <value/>
      </setting>
      <setting name="authenticated_user" serializeAs="String">
        <value/>
      </setting>
    </TAMI.My.MySettings>
  </userSettings>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="itextsharp" publicKeyToken="8354AE6D2174DDCA" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-5.3.2.0" newVersion="5.3.2.0"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

我一直在使用的代码

        For b As Integer = 0 To lboxconv.Items.Count - 1
            Application.DoEvents()
            Dim extension = Microsoft.VisualBasic.Right(b, 3)
            Dim doc As New Document()
            Dim File_Type As String
            File_Type = Replace(lboxconv.Items(b), ".png", ".pdf", vbTextCompare)
            Dim writer As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(File_Type, FileMode.Create))
            doc.Open()
            Dim imgpath As String = lboxconv.Items(b)
            Dim png As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imgpath)
            png.ScaleToFit("500", "500")
            png.Alignment = Element.ALIGN_CENTER
            doc.Add(png)
            doc.Close()
        Next
有人请帮忙!我很绝望,耗尽时间和答案。

0 个答案:

没有答案