文件上传概念数据存储在文件夹中,并在网站上显示链接 [英] file upload concept data store in folder and link to be displayed in website
问题描述
大家好,
请给我代码,以便使用vb代码在asp.net中将文件上传到数据库中,并以超链接的形式显示在网站上.如果删除,则应从数据库中删除该文件.
请为此给我逐步的说明和代码.
编辑-从答案移到
大家好,
请告诉我我哪里出错了,并给出以下错误
Hello All,
Please give me code for file upload in asp.net using vb code into database and display on to a website as a hyperlink.if it is delete the file should be deleted from database.
please give me step wise instruction and code for this.
EDIT - Moved from answer
Hello All,
Please tell me where i went wrong it giving the following error
Access to the path ''C:\Documents and Settings\ananth\My Documents\Visual Studio 2005\WebSites\text\FileUpload'' is denied.
下面是使用iam的代码
Below is the code iam using
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO
Imports System.Data
Imports System.Configuration
Imports System.Security.Principal
Imports System.Web.Security
Partial Class FileUpload
Inherits System.Web.UI.Page
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim rdr As SqlDataReader
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim ra As Integer
If Not (myFile.PostedFile Is Nothing) Then
Dim intFileNameLength As Integer
Dim strFileNamePath As String
Dim strFileNameOnly As String
'Logic to find the FileName (excluding the path)
strFileNamePath = myFile.PostedFile.FileName
intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\")
strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath) - intFileNameLength) + 2)
myFile.PostedFile.SaveAs("C:\Documents and Settings\ananth\My Documents\Visual Studio 2005\WebSites\text\FileUpload" & strFileNameOnly)
lblFileContentType.Text = "File Upload Success:-" & CStr(myFile.PostedFile.ContentLength) & " bytes"
'lblFileContentType.Text = "Content type: " & MyFile.PostedFile.ContentType
'lblFileSize.Text = "File size: " & CStr(myFile.PostedFile.ContentLength) & " bytes"
myConnection = New SqlConnection("server=172.18.0.6;uid=sa;pwd=logmein;database=ananth")
'you need to provide password for sql server
myConnection.Open()
myCommand = New SqlCommand("Insert into fileupload(filename,link) values('" + TextBox1.Text + "','" + FileUpload1.FileName + "')", myConnection)
ra = myCommand.ExecuteNonQuery()
'Since no value is returned we use ExecuteNonQuery
Response.Write("Records Inserted" & ra)
myConnection.Close()
End If
End Sub
End Class
推荐答案
请考虑购买一本编程书籍,阅读它,学习使用google,并通常尝试成为一名程序员,而不是要求其他人免费做您的工作而没有尝试.论坛答复无法为您提供所需的所有代码,并且此站点以及其他地方的大量文章都将向您确切显示该怎么做.如果您因为仍然很不了解编程而陷入僵局,那么我敢肯定,当您在此处发布特定问题,代码段和对您的解释时,我们很乐意回答''尝试过并且被困在哪里.
Please consider buying a programming book, reading it, learning to use google, and in general trying to become a programmer instead of asking other people to do your work for free without even trying. There is no way a forum reply can give you all the code you need, and there''s tons of articles on this site and elsewhere that would show you exactly what to do. If you got stuck still, because it''s clear you don''t know much about programming, then I''m sure we''d love to answer when you posted specific questions here, with code snippets and explanations of what you''ve tried and where you are stuck.
开始 ^ ].
访问路径``C:\ Documents和设置\ ananth \我的文档\ Visual Studio 2005 \ WebSites \ text \ FileUpload''被拒绝
Access to the path ''C:\Documents and Settings\ananth\My Documents\Visual Studio 2005\WebSites\text\FileUpload'' is denied
该错误说明自身,您无权访问该特定文件夹.因此,请设置该文件夹的权限.
ASP.NET用户对您的应用程序文件夹没有权限 [ ^ ]
我的建议是不要在C:\ Drive中使用文件夹,而要使用其他任何驱动器.
The error says itself, You have no permission to that particular folder. So set the permission for that folder.
ASP.NET User Does Not Have Permissions to Your Application Folder[^]
My suggestion is don''t use folders in C:\ Drive, use any other drives.
这篇关于文件上传概念数据存储在文件夹中,并在网站上显示链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!