2012-06-18 44 views
1

我正在使用WinCE操作系統的經典ASP。我想從本地機器的WinCE和Save上傳文件。請分享必要的文件上傳JScript功能,我可以把它放在一個包含文件中。謝謝。上傳按鈕上的文件點擊asp

+0

謝謝你提醒德里克,我已經接受了答案。現在請幫助我上傳文件。 – user1409360

+0

我提出了這個問題,讓更多的人可以幫助你。 –

回答

0

我沒有關於asp經典的信息,但我已經使用了Asp.net,你可以使用asp來接收文件以便上傳從wince使用廣告文件可以開發應用程序使用C#這裏是一個例子。

其客戶WinCE應用程序代碼功能上傳(路徑字符串,字符串文件名)取文件的路徑和文件名作爲輸入,並張貼到網頁現在

#region Upload 
public bool Upload(string FilePath, string FileName) 
{ 
string Url = "HTTP://test.mtsonweb.com/fileupload.ashx"; // Change it to your page name 
string BytesConfirmedReceived = ""; 
int BytesSent = 0; 
bool Ret = false; 
ASCIIEncoding encoding = new ASCIIEncoding(); 
try 
{ 

if (File.Exists(FilePath +"\\"+ FileName) == false) { return true; } 

//FileInfo oInfo = new FileInfo(FilePath + "\\" + FileName); 
//BytesSent = Convert.ToInt32(oInfo.Length.ToString()); 

Url += "?myfile=" + FileName.Trim(); 

FileStream fr = new FileStream(FilePath + "\\" + FileName, FileMode.Open); 

BinaryReader r = new BinaryReader(fr); 
byte[] FileContents = r.ReadBytes((int)fr.Length); 
BytesSent = FileContents.Length; 

r.Close(); 
fr.Close(); 

WebRequest oRequest = WebRequest.Create(Url); 

oRequest.Method = "POST"; 

oRequest.Timeout = 15000; 

oRequest.ContentLength = FileContents.Length; 

Stream oStream = oRequest.GetRequestStream(); 

BinaryWriter oWriter = new BinaryWriter(oStream); 

oWriter.Write(FileContents); 

oWriter.Close(); 

oStream.Close(); 

WebResponse oResponse = oRequest.GetResponse(); 
BytesConfirmedReceived = new StreamReader(oResponse.GetResponseStream(), 
Encoding.Default).ReadToEnd(); 

oResponse.Close(); 

if (BytesSent.ToString() == BytesConfirmedReceived.Trim()) 
{ 
Ret = true; 
} 

} 
catch (Exception ex) 
{ 
MessageBox.Show(ex.Message); 
} 
return Ret; 

} 
#endregion 

你頁面,您可以處理用腳本文件上傳無論你想要什麼,我已經使用asp.net與c#作爲後端,以下是頁面的源代碼:

<%@ WebHandler Language="C#" Class="FileUpload" %> 
using System; 
using System.Xml; 
using System.Data; 
using System.Web; 
using System.IO; 
using System.Text; 
using System.Runtime.InteropServices; 
using System.Drawing; 

public class FileUpload : IHttpHandler 
{ 
public void ProcessRequest(HttpContext oContext) 
{ 

int BytesSent = 0; 
//string LocalPath = @"C:\Inetpub\wwwroot\"; 

string MyFile = ""; 


try 
{ 

MyFile = oContext.Request["myfile"].ToString().Trim(); 
MyFile = HttpContext.Current.Server.MapPath("~/Demo/Files/" + 

ASCIIEncoding encoding = new ASCIIEncoding(); 

BytesSent = oContext.Request.TotalBytes; 

Class1 obj = Class1.GetInstance(); 

obj.FileName = MyFile; 
obj.FileLength = BytesSent; 

byte[] InComingBinaryArray = 
oContext.Request.BinaryRead(oContext.Request.TotalBytes); 
obj.Data = InComingBinaryArray; 

if (File.Exists(MyFile) == true) 
{ 
File.Delete(MyFile); 
} 

FileStream fs = new FileStream(MyFile, FileMode.CreateNew); 
BinaryWriter w = new BinaryWriter(fs); 
w.Write(InComingBinaryArray); 
w.Close(); 
fs.Close(); 

FileInfo oInfo = new FileInfo(MyFile); 
long a = (long)BytesSent; 

oContext.Response.Write(oInfo.Length.ToString()); 

} 
catch (Exception err) { oContext.Response.Write(err.Message); } 

} 

public bool IsReusable { get { return true; } } 

}