2012-06-18 2 views
1

WinCE OS로 고전적인 ASP 작업 중입니다. WinCE에서 파일을 업로드하고 로컬 컴퓨터에 저장하고 싶습니다. 포함 파일에 넣을 수있는 파일 업로드에 필요한 JScript 함수를 공유하십시오. 고맙습니다.버튼에 파일 업로드 asp로 클릭하십시오

+0

Derek를 상기시켜 주셔서 감사합니다, 나는 대답을 수락했습니다. 이제 파일 업로드를 도와주세요. – user1409360

+0

나는 더 많은 사람들이 당신을 도울 수 있도록 질문을 upvoted. –

답변

0

더 나은 방법은 여기

파일 업로드 예입니다 .. jQuery를 같은 .. 자바 스크립트 라이브러리를 사용하는 것입니다 ..

http://pixelcone.com/jquery/ajax-file-upload-script/

How can I upload files asynchronously?

건배 :)

+0

WinCE OS 및 고전 ASP에서와 같이 JQuery 플러그인을 사용할 수 없습니다. 다른 방법을 제안하십시오. – user1409360

+0

당신은 순수한 자바 스크립트 솔루션이 필요합니까? – dhroove

+0

예. 도와주세요. 고맙습니다. – user1409360

0

asp 고전에 대한 정보가 없지만 Asp.net을 사용했고 asp를 사용하여 파일을 받아서 uplo 질겁 사용에서 광고 파일은 C#을 사용하여 응용 프로그램을 개발할 수 있습니다 여기에 예제입니다.

는 그것의 클라이언트 주춤 응용 프로그램 코드의 기능 업로드 (문자열 경로, 문자열 파일 이름) 파일 경로를 소요하고 당신이 파일이 스크립트를 사용하여 업로드 처리 할 수 ​​있습니다 페이지의

#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 

이제 웹 페이지에 입력 및 우편으로 파일 이름 당신이 원하는대로, 나는 백 엔드로 C# asp.net을 사용하고 아래 페이지 소스 :

<%@ 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; } } 

}