Upload center problems(1)

shahab

Junior Contributor
Joined
Aug 14, 2003
Messages
206
Location
Iran(Middle East)
Dear friends,
I had uploaded the sound files (Mp3, wav format) To an Upload center successfully.
What I had planed is something like this:
• The Database I have planed only saves the name of the files that will upload by users
SqlParameter paramVoiceAddress = new SqlParameter(
"@VoiceAddress", SqlDbType.Char , 50);
paramVoiceAddress.Value = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf(@"\")+1);
objCmd.Parameters.Add(paramVoiceAddress);
--------------------------------------------------------------------------------------------------------------------
** The uploaded files will place in www root \Project name \Music\
void UploadVoiceFile()
{
if (File1.PostedFile != null)
{
try
{
string FileNameOnServer = @"D:\Inetpub\wwwroot\School\VoiceFiles\" + File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf(@"\")+1);
File1.PostedFile.SaveAs(FileNameOnServer);
Label3.Text = "Upload Successful!";
}
catch (Exception ex)
{
Label3.Text = "Error saving file <b>D:\\" +
File1.Value + "</b><br>" + ex.ToString();
}
}
}
--------------------------------------------------------------------------------------------------------------------
***
Now my questions are:
1- What is the best way to save files in MS Sql server (The file or its name?)
2- What is the best way to showing the uploaded files to users in order to download them without on problem? (Please suggest more than one way and compare the best ones!)
3- Are there any security issues on putting the music files directly in wwwroot?
4- When the user does not upload a file (It is possible –Sending later) this message is shown:
System.IO.DirectoryNotFoundException: Could not find a part of the path "D:\Inetpub\wwwroot\School\VoiceFiles\". at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at
So many thanks.
shahab
 
1. You should not store files/images in SQL server, it is slow and takes more space. Just store the file name and/or optional path to where the file sits on the server
2. Do a select of these file names to the user. when they want to download it, you push these files to them thru your asp.net page.
3. See #2, you push these files to the user thru code becuase you should not store them in your wwwroot. Well, at least that is my opinion. This way, they cant simply browse to it and you dont have to implement another layer of security to protect them if they are in your website directory.
4. As far as your error, you need to take care of that in your programming, dont attempt to save the file if they are not uploading anything :p
 
As far as your error, you need to take care of that in your programming, dont attempt to save the file if they are not uploading anything
Thanks kahloa001,
But i was consider about it!:
if (File1.PostedFile != null)
{
try
{
 
Back
Top