Jump to content

uploading file


wooikeim

Recommended Posts

I have a problem uploading file, even though the file is brose and when i click on upload then it always show me "uploade failed"can anyone find out where is my mistake? thank youSub Upload_Click(source As Object, e As EventArgs)Dim savePath As String = "C:\Inetpub\wwwroot\tution\files" Try Dim postedFile = uploadedFile.PostedFile Dim filename As String = System.IO.Path.GetFileName(postedFile.FileName) Dim contentType As String = postedFile.ContentType Dim contentLength As Integer = postedFile.ContentLength postedFile.SaveAs(savePath) message.Text = "uploaded" Catch exc As Exception message.Text = "uploade failed" End Try End Sub

Link to comment
Share on other sites

do this so we can get the real error message

Sub Upload_Click(source As Object, e As EventArgs)Dim savePath As String = "C:\Inetpub\wwwroot\tution\files"TryDim postedFile = uploadedFile.PostedFileDim filename As String = System.IO.Path.GetFileName(postedFile.FileName)Dim contentType As String = postedFile.ContentTypeDim contentLength As Integer = postedFile.ContentLengthpostedFile.SaveAs(savePath)message.Text = "uploaded"Catch exc As Exceptionmessage.Text = "uploade failed<br/><br/>" & exc.MessageEnd TryEnd Sub

It is probably because the ASP.NET worker account does not have permission to write to the target folder.

Link to comment
Share on other sites

do this so we can get the real error message
Sub Upload_Click(source As Object, e As EventArgs)Dim savePath As String = "C:\Inetpub\wwwroot\tution\files"TryDim postedFile = uploadedFile.PostedFileDim filename As String = System.IO.Path.GetFileName(postedFile.FileName)Dim contentType As String = postedFile.ContentTypeDim contentLength As Integer = postedFile.ContentLengthpostedFile.SaveAs(savePath)message.Text = "uploaded"Catch exc As Exceptionmessage.Text = "uploade failed<br/><br/>" & exc.MessageEnd TryEnd Sub

It is probably because the ASP.NET worker account does not have permission to write to the target folder.

beside "uploaded fail" it show me --> Access to the path "C:\Inetpub\wwwroot\tution\files" is denied. so may i know what is the solution?
Link to comment
Share on other sites

I'll assume you are using Windows XP. If you are using Windows Server 2003 replace ASPNET with NETWORK SERVICE in the instructions below.Right click the target folder and choose Properties.Switch tot eh Security tab.If the ASPNET user is not shown in the list, add it.Click on the ASPNET user account and make sure that the Modify option is checked.

Link to comment
Share on other sites

then use the instructions as is.

Right click the target folder and choose Properties.Switch tot eh Security tab.If the ASPNET user is not shown in the list, add it.Click on the ASPNET user account and make sure that the Modify option is checked.
Link to comment
Share on other sites

You say about:-"Right click the target folder and choose Properties.Switch to the Security tab.If the ASPNET user is not shown in the list, add it.Click on the ASPNET user account and make sure that the Modify option is checked."I can't find security tab at all?only got General, sharing, web sharing and customize.sorry for disturbing.

Link to comment
Share on other sites

The default setting for the file system is "simple" file sharing. This does not show the security tab. Follow the article below to disable simple file sharing and the security tab will be visible.http://support.microsoft.com/kb/307874
(=_=") I had clear the Use simple file sharing. And created ASPNET(machinename/ASPNET) Modify option is checked, but it still show me Access to the path "C:\Inetpub\wwwroot\tution\files" is denied. I really get Frustrated......:)
Link to comment
Share on other sites

okay so you applied that tot he "files" folder? Try checking the "Full Control" option for ASPNET. If that doesn't work apply "Full Control" tot he Everyone account for that folder. This is not recommended as it leaves your system open but we will do it just to see if the error is indeed permissions releated.

Link to comment
Share on other sites

okay so you applied that tot he "files" folder? Try checking the "Full Control" option for ASPNET. If that doesn't work apply "Full Control" tot he Everyone account for that folder. This is not recommended as it leaves your system open but we will do it just to see if the error is indeed permissions releated.
Well, i had try to put it as full control, but still the same. :)
Link to comment
Share on other sites

ok so it is not a file system permission issue, it must be an IIS permissions issue.Are you familiar with the IIS manager interface? If so make sure your application has read and write permissions.If your not follow these instructionsopen iis manger (control panel/administrative tools/internet information services)expand the websites node.right click your website and choose propertiesgo to the Home directory tab and make sure Read and Write are checked.

Link to comment
Share on other sites

I seriously don't know how to do this in VB, but in C# you'd want to make sure you are trying to save the file to something like C:\Inetpub\wwwroot\tuition\files\MYFILE.EXT rather than C:\Inetpub\wwwroot\tuition\files. I think Windows is having a cow that you are trying to save a file as a directory.C#:

string savePath = "C:\\Inetput\\wwwroot\\tuition\\files\\";...postedFile.SaveAs(savePath + filename);

Link to comment
Share on other sites

Well, it still the same, don't know what happen there. i had try debug it by putting this and it successful store in database, but the file cant save in the location(C:\Inetpub\wwwroot\tution\file).Dim savePath As String = "C:\Inetpub\wwwroot\tution\file" Try Dim postedFile = uploadedFile.PostedFile Dim filename As String = System.IO.Path.GetFileName(postedFile.FileName) Dim contentType As String = postedFile.ContentType Dim contentLength As Integer = postedFile.ContentLength Dim myConnection As SqlConnection = New SqlConnection("server=(local);database = MegaArif; trusted_connection= yes") Dim mycommand as sqlCommand= new sqlCommand("insert into notes(content, subject_id) values('"& FileName &"', '"& lblsubjectid.text &"') ",myConnection) mycommand.connection.open() mycommand.executeNonQuery() mycommand.connection.close() postedFile.SaveAs(savePath) message.Text = "uploaded" Catch exc As Exception message.Text = "uploade failed <br/><br/>" & exc.MessageEnd TryEnd SubI had also try another way, reference from http://www.superdotnet.com/Article.aspx?ArticleID=26Another error msg when i use the method.(Exception has been thrown by the target of an invocation)

Link to comment
Share on other sites

If "file" (or "files") is a directory, you can't save a file with that path. What you can do is save a file in that directory.You are still running:

postedFile.SaveAs(savePath)

Rather than

postedFile.SaveAs(savePath & "\" & filename)

Link to comment
Share on other sites

If "file" (or "files") is a directory, you can't save a file with that path. What you can do is save a file in that directory.You are still running:
postedFile.SaveAs(savePath)

Rather than

postedFile.SaveAs(savePath & "\" & filename)

Oh thank you very much, it work after i use "postedFile.SaveAs(savePath & "\" & filename)" , thank a lot man.and also thanks to aspnetguy,jesh,pulpfiction.i been doing this for whole day :) I am newbie in .net
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...