2013-03-29 50 views
0

早安/下午好,我心中已經被檢驗出VIN掃描器BarcodeLib終於得到它的工作使用的Visual Studio 2012C#.net或ASP.net錯誤?

之前,我會硬編碼的圖像轉換成讀者喜歡

string[] results = BarcodeReader.read(@"C:/scan/image.jpg", BarcodeReader.CODE39); 

但現在因爲我想在我的asp中使用input type,它會停止顯示結果。

我的問題是,爲什麼在這一點上什麼都不輸出?

我的想法是,也許這是if語句。

這裏的編碼

namespace testWebBarcode 
{ 
     protected void bnvinoneclick_Click(object sender, EventArgs e) 
     { 
      HttpPostedFile fileImage = Request.Files["FileUpload"]; 

      if (fileImage != null && fileImage.ContentLength > 0) 
      { 
       string imageFileName = Path.GetFileName(fileImage.FileName); 

       //reads barcode (@"filename", BarcodeReader.TypeBarcode) 
       string[] results = BarcodeReader.read(imageFileName, BarcodeReader.CODE39); 
       string answer = string.Empty; 
       for (int i = 0; i < results.Length; i++) 
        { 
         answer = results[i]; 
        } 
       string finalVin = "The vin is: " + answer; 
       lblvin.Text = finalVin; 
      } 

     } 

} 

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="testWebBarcode._Default" %> 

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> 
    <script type="text/javascript"> 
     function readURL() 
      { 

      document.getElementById('<%=bnvinoneclick.ClientID%>').click(); 
      } 

    </script> 


</asp:Content> 
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> 

    <p> 
     <asp:Label ID="lblvin" runat="server" Text=""></asp:Label> 
    </p> 
    <p> 
     <asp:Label ID="Label1" runat="server" Text=""></asp:Label> 
    </p> 
    <p> 

     <input type="file" accept="image/*" runat="server" id="FileUpload" onchange="readURL();" /> 



     <asp:Button ID="bnvinoneclick" runat="server" Text="Check vin" 
      onclick="bnvinoneclick_Click" /> 
      </p> 

</asp:Content> 

感謝您抽出寶貴的時間來審查我的問題,如果你回答道

回答

0

你可能會發現fileImage.FileName爲您提供client上的文件名稱,因此您無法在服務器中使用它(注意您的.NET代碼在服務器端執行而不是客戶端執行)。儘管你可能想要的是:

  1. 用戶上傳從文件說C:\ MYFILES \ uploadme.jpg(這一點,當你在你的代碼中使用FileName屬性,你可能會得到的路徑)
  2. 節省文件到你的服務器(例如一個D:\<MyServerDirectory>\UploadedImages文件夾或類似的東西)
  3. 您與文件工作,一旦它保存到服務器

我建議將其保存(見this爲例),然後通過你保存到哪裏的路徑(c考慮到它現在是「服務器」路徑與客戶端路徑)Barcode方法

+0

敬畏,所以我只是錯過了幾個步驟。感謝您的鏈接 – DarkAngel

+0

沒有問題,請將問題標記爲已回答,如果它解決了您的問題(並作爲向任何其他同事提出的問題) – nkvu

0

在你的第一個「工作」的例子,你'使用文件系統路徑讀取映像(即從文件系統讀取文件)

在第二個示例中,您正在傳入來自HttpPostedFile對象的文件名。你需要在這裏讀取輸入流的內容 - 我的猜測是條形碼讀取方法試圖在文件系統中查找文件,並且不能..?

閱讀HttpPostedFile輸入流中的內容,然後將其保存到硬盤上進行閱讀,如果你不能簡單地傳遞一個字節數組條形碼11b的讀法

http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.aspx

+0

我只是沒有得到任何錯誤。所以我不完全確定。我會再次瀏覽網站,看看是否有任何東西吸引我的目光。 – DarkAngel

+0

你需要閱讀'fileImage.InputStream' - *必須* – Moho