如何实现这样的上传? 是word文件,由于安全方面的考虑,不能直接存放到数据库中 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用vb.net将文件上传给一个asp.net页面----不懂你具体要做什么要加密文件内容? 具体的说,我要将一个指定的文件上传到web服务器上。使用<input type=file>不能指定文件名,而必须要用户选择。因此使用嵌入网页的windows控件,但是又老是不成功。代码如下: '*保存正文信息 Public Function Save() As Boolean Dim objDocContent As Object Dim dsDoc As DataSet Dim drow As DataRow Try 'dsDoc = New DataSet() 'dsDoc.Tables.Add("DocContent") 'dsDoc.Tables(0).Columns.Add(STR_PARAMETER_TABLE_NAME, Type.GetType("System.String")) 'dsDoc.Tables(0).Columns.Add(STR_PARAMETER_RECORDID_NAME, Type.GetType("System.String")) 'dsDoc.Tables(0).Columns.Add(STR_PARAMETER_DOC_NAME, Type.GetType("System.Object")) 'drow = dsDoc.Tables(0).NewRow 'drow(STR_PARAMETER_TABLE_NAME) = mstrTableName 'drow(STR_PARAMETER_RECORDID_NAME) = mintRecordId.ToString.Trim objDocContent = ReadFileToObject(mstrLocalDocName) 'drow(STR_PARAMETER_DOC_NAME) = System.Convert.ToBase64String(objDocContent, _ ' 0, _ ' objDocContent.Length) 'drow(STR_PARAMETER_DOC_NAME) = ReadFileToObject(mstrLocalDocName) 'dsDoc.Tables(0).Rows.Add(drow) 'objDocContent = dsDoc.GetXml() Dim ls As HttpWebRequest Dim rs As Stream ls = Net.WebRequest.Create(mstrHttpFilePath & mstrSaveDocAsp) ' 设置某些 WebRequest 属性 ls.Method = "POST" ls.ContentType = "garl.doc" rs = ls.GetRequestStream Dim tt() As Byte tt = objDocContent MsgBox("ok") rs.Write(tt, 0, tt.Length) rs.Close() '*删除已经下载的文档 'DeleteFile() Catch ex As Exception Prompt("保存正文信息失败!" & Chr(13) _ & " 原因如下:" & Chr(13) _ & " " & ex.Message) Save = False Finally drow = Nothing 'dsDoc.Dispose() dsDoc = Nothing objDocContent = Nothing End Try End Function 嵌入网页的windows控件也有安全性限制的 namespace KumsalNet.WoiseUpload{ using System; using System.Net; using System.Windows.Forms; class MainForm : Form { public MainForm() { Text = "Plase Select and Upload File Wave File"; System.Windows.Forms.Button button1; button1 = new System.Windows.Forms.Button(); button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; button1.Location = new System.Drawing.Point(20, 20); button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; button1.Size = new System.Drawing.Size(100, 26); button1.TabIndex = 5; button1.Text = "TestButton"; button1.Click += new System.EventHandler(button1_Click); this.Controls.Add(button1); } private void button1_Click(object sender, EventArgs e) { // MessageBox.Show("You pressed the test button") ; FileUpload fileupload= new FileUpload(@"c:\faturalar.zip",newUri("http://localhost:8080/SaweFie.aspx")); MessageBox.Show(fileupload.Send().ToString()); } public static void Main(string[] args) { Application.Run(new MainForm()); } } public class FileUpload{ WebClient WC; string File; Uri Url; public FileUpload(string Dosya,Uri Hedef) { WC=new WebClient(); File =Dosya; Url=Hedef; } public bool Send(){ try{ WC.UploadFile(Url.ToString(),"POST",File); return true; } catch(Exception exx) { Console.WriteLine(exx.Message); return false; /*if(e.Message.Length>0) { MessageBox.Show(e.Message); }*/ } } }}SaweFie.aspx is there ...<%@ Page Language="C#" %><script runat="server"> // Insert page code here // void Page_Load(Object sender, EventArgs e) { try { foreach(string postedfile in Request.Files) { HttpPostedFile file= Request.Files.Get(postedfile); file.SaveAs(@"c:\dodnet\"+file.FileName); } } catch(Exception Ex) { Response.Write(Ex.Message); } }</script><html><head></head><body> <form runat="server"> <!-- Insert content here --> </form></body></html> http://www.csdn.net/Expert/TopicView1.asp?id=1084653http://www.csdn.net/Expert/TopicView1.asp?id=1081220也请zeaing回答一下吧! 紧急求救!!!不间断向左滚动图片怎么搞。从数据库中读取的 asp.net(C#)批量打印的问题 关于标识列求助 高手请进,问题。 网站分类 如何在一个虚拟空间上放几个Asp.Net的项目呢? 这段老提示必须声明标量变量"@MemberName" 如何进行条件绑定 怎样将dataset中的数据行相同的,只保留1行 为什么我的新闻显示页面没有分段啊? 要不要分啊,快来吧:) 初试asp.net
----不懂你具体要做什么要加密文件内容?
'*保存正文信息
Public Function Save() As Boolean
Dim objDocContent As Object
Dim dsDoc As DataSet
Dim drow As DataRow
Try
'dsDoc = New DataSet()
'dsDoc.Tables.Add("DocContent")
'dsDoc.Tables(0).Columns.Add(STR_PARAMETER_TABLE_NAME, Type.GetType("System.String"))
'dsDoc.Tables(0).Columns.Add(STR_PARAMETER_RECORDID_NAME, Type.GetType("System.String"))
'dsDoc.Tables(0).Columns.Add(STR_PARAMETER_DOC_NAME, Type.GetType("System.Object"))
'drow = dsDoc.Tables(0).NewRow
'drow(STR_PARAMETER_TABLE_NAME) = mstrTableName
'drow(STR_PARAMETER_RECORDID_NAME) = mintRecordId.ToString.Trim
objDocContent = ReadFileToObject(mstrLocalDocName)
'drow(STR_PARAMETER_DOC_NAME) = System.Convert.ToBase64String(objDocContent, _
' 0, _
' objDocContent.Length)
'drow(STR_PARAMETER_DOC_NAME) = ReadFileToObject(mstrLocalDocName)
'dsDoc.Tables(0).Rows.Add(drow)
'objDocContent = dsDoc.GetXml()
Dim ls As HttpWebRequest
Dim rs As Stream
ls = Net.WebRequest.Create(mstrHttpFilePath & mstrSaveDocAsp)
' 设置某些 WebRequest 属性
ls.Method = "POST"
ls.ContentType = "garl.doc"
rs = ls.GetRequestStream
Dim tt() As Byte
tt = objDocContent
MsgBox("ok")
rs.Write(tt, 0, tt.Length)
rs.Close() '*删除已经下载的文档
'DeleteFile()
Catch ex As Exception
Prompt("保存正文信息失败!" & Chr(13) _
& " 原因如下:" & Chr(13) _
& " " & ex.Message)
Save = False
Finally
drow = Nothing
'dsDoc.Dispose()
dsDoc = Nothing
objDocContent = Nothing
End Try
End Function
using System;
using System.Net;
using System.Windows.Forms; class MainForm : Form
{ public MainForm()
{
Text = "Plase Select and Upload File Wave File"; System.Windows.Forms.Button button1; button1 = new System.Windows.Forms.Button(); button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
button1.Location = new System.Drawing.Point(20, 20);
button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
button1.Size = new System.Drawing.Size(100, 26);
button1.TabIndex = 5;
button1.Text = "TestButton";
button1.Click += new System.EventHandler(button1_Click);
this.Controls.Add(button1);
}
private void button1_Click(object sender, EventArgs e) {
// MessageBox.Show("You pressed the test button") ; FileUpload fileupload= new FileUpload(@"c:\faturalar.zip",new
Uri("http://localhost:8080/SaweFie.aspx"));
MessageBox.Show(fileupload.Send().ToString());
} public static void Main(string[] args)
{
Application.Run(new MainForm());
}
} public class FileUpload{ WebClient WC;
string File;
Uri Url; public FileUpload(string Dosya,Uri Hedef)
{
WC=new WebClient();
File =Dosya;
Url=Hedef;
}
public bool Send(){
try{
WC.UploadFile(Url.ToString(),"POST",File);
return true;
}
catch(Exception exx)
{
Console.WriteLine(exx.Message);
return false;
/*if(e.Message.Length>0)
{
MessageBox.Show(e.Message);
}*/ } }
}}SaweFie.aspx is there ...
<%@ Page Language="C#" %>
<script runat="server"> // Insert page code here
// void Page_Load(Object sender, EventArgs e) {
try {
foreach(string postedfile in Request.Files)
{
HttpPostedFile file=
Request.Files.Get(postedfile);
file.SaveAs(@"c:\dodnet\"+file.FileName);
}
}
catch(Exception Ex)
{
Response.Write(Ex.Message);
} }</script>
<html>
<head>
</head>
<body>
<form runat="server">
<!-- Insert content here -->
</form>
</body>
</html>
http://www.csdn.net/Expert/TopicView1.asp?id=1081220
也请zeaing回答一下吧!