Fileupload控件帮助 [英] Fileupload control help
本文介绍了Fileupload控件帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在做样本注册页面。我碰巧在3层架构中使用文件上传控件。我用谷歌搜索并检查了解它但仍然我的排队是如何在3层使用。我的意思是流动。还有在数据库中。例如,它的数据类型是什么,任何帮助....赞。
解决方案
我同意马德拉的Kumar,但我想解释一下流动多一点...
好的,通常你不会将文件插入数据库本身,而是在你的网站上有一个文件夹(在库马尔''例子上传)。然后你会在数据库表中有一个引用该文件的字段(例如nvarchar(500))...
如果你有一个数据库的示例(C#)使用表UserFiles它将有一个字段FilePath ...
// 您网站中文件夹的路径
string virtualPath = 〜/ Uploads /;
// 要上传文件,您需要一个文件夹的物理路径
string physicalPath = Server.MapPath(virtualPath);
// 这确保文件名是唯一的
string fileName = GUID.NewGuid()。ToString();
// 获取文件的扩展名
string extension = System.IO.Path.GetExtension(fileUpload.FileName);
// 现在可以将文件实际上传到服务器......
fileUpload.SaveAs(System.IO.Path.Combine(physicalPath,fileName + extension));
// 现在要保存数据库的路径,你必须调用插入的方法数据到表中我将使用一个名为UserFiles的示例类和一个静态方法InsertFile,它接受文件路径并将其插入表中
UserFiles.InsertFile(virtualPath + fileName + extension);
我只是输入了我的头脑,但如果我犯了任何错误,Intellisense会帮助你。
HI JACK
PLS找到以下示例代码您可以获得一些想法
Dim Dt As 新 DataTable
Dim MyCommand As OleDbDataAdapter
Dim filename As 字符串 = 我 .FileUpload1.PostedFile.FileName
Dim 无效 As Boolean = 错误
Dim validfilename 作为 字符串 = 。PDF;
Dim ext As String = System.IO.Path.GetExtension(filename)
如果 ext<> 。& validfilename 然后
isvalid = False
返回 Dt
退出 功能
Else
结束 如果
Dim savepath 作为 字符串 = Server.MapPath(< span class =code-string> 〜/ Uploads /)
Me .FileUpload1.PostedFile.SaveAs(savepath& System.IO.Path.GetFileName(filename))
Dim fileupload 作为 字符串 = savepath
Dim uploadfile As String = Server.MapPath( 〜/ Uploads /)+ System.IO.Path.GetFileName(filename)
Hi all,
I am doing a sample registration page. I happened to use file upload control in 3 tier architecture. I googled it and checked got some understanding about it but still my queation is how to use in 3 tier. i mean the flow. and also in database. For example, What is the datatype for it, any help....appreciated.
解决方案
I agree with Kumar from madras, but I would just like to explain the flow a bit more...
Ok so usually you would not insert the file into the database itself, but rather have a folder in your website (in Kumar''s example Uploads). Then you would have a field in your database table that references to the file (e.g. nvarchar(500))...
Example (C#) if you have a Database with a table UserFiles it would have a field FilePath...
//The path of your folder inside your website string virtualPath = "~/Uploads/"; //To upload a file you need a physical path to the folder string physicalPath = Server.MapPath(virtualPath); //This ensures that the file name is unique string fileName = GUID.NewGuid().ToString(); //Grab the extension of the file string extension = System.IO.Path.GetExtension(fileUpload.FileName); //Ok now to actually upload the file to the server... fileUpload.SaveAs(System.IO.Path.Combine(physicalPath,fileName + extension)); //Now to save the path to the database you have to call your method which inserts data into the table I'm just going to use a example class called UserFiles and a static method InsertFile that takes the filepath and inserts it into the table UserFiles.InsertFile(virtualPath+fileName+extension);
I just typed this of the top of my head, but Intellisense will help you out if I made any mistakes.
HI JACK
PLS FIND THE BELOW SAMPLE CODE YOU CAN GET SOME IDEA
Dim Dt As New DataTable Dim MyCommand As OleDbDataAdapter Dim filename As String = Me.FileUpload1.PostedFile.FileName Dim isvalid As Boolean = False Dim validfilename As String = ".PDF"; Dim ext As String = System.IO.Path.GetExtension(filename) If ext <> "." & validfilename Then isvalid = False Return Dt Exit Function Else End If Dim savepath As String = Server.MapPath("~/Uploads/") Me.FileUpload1.PostedFile.SaveAs(savepath & System.IO.Path.GetFileName(filename)) Dim fileupload As String = savepath Dim uploadfile As String = Server.MapPath("~/Uploads/") + System.IO.Path.GetFileName(filename)
这篇关于Fileupload控件帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文