Jump to content
Sign in to follow this  
wooikeim

uploading file

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

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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......:)

Share this post


Link to post
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.

Share this post


Link to post
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. :)

Share this post


Link to post
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.

Share this post


Link to post
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);

Share this post


Link to post
Share on other sites

Its the same in VB just remove the ";". i kinda had the similar problem, remove the try...catch block and see if it works...

postedFile.SaveAs(savePath + fname)

Share this post


Link to post
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)

Share this post


Link to post
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)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...