Server.mappath
FileUpload.Saveas(Server.Mappath("newfolder"+filename)) what is it meaning?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dinkar ChavhanRank #1,132 · 1.6K reputationPosted Apr 19, 2011, 8:57 PM EDT
{
Audio Song Uploading
In this Article we see how to upload Audio or MP3 song in Database and also Aplication folder like Audio.This is simple code useful for Developer
So lets see step by step procedure
Step 1) Take textbox and fileupload control and Button and lable
Step 2)Create table like
{
CREATE TABLE [dbo].[Audio](
[id] [int] NOT NULL,
[song] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_Audio] PRIMARY KEY CLUSTERED
(
}
Step 3)Now write stored procedure
{
ALTER procedure Sp_Audio(@id int,@song varchar(50))
As
Begin
insert into Audio(id,song)values(@id,@song)
end
}
}
Step 4)Now double click on Button and write code
{
SqlConnection cn = new SqlConnection("Give Path");
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cn.Open();
cmd.CommandText = "Sp_Audio";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", TextBox1.Text);
cmd.Parameters.AddWithValue("@song", FileUpload1.FileName);
int i=cmd.ExecuteNonQuery();
if (FileUpload1.HasFile)
{
string fname = FileUpload1.FileName.ToString();
string folderpath = "~/Audio";
string path = HttpContext.Current.Server.MapPath(folderpath);
FileUpload1.PostedFile.SaveAs(path + "\\" + fname);
Label1.Text = "file uploaded successfully";
}
}
}
Step 5)Now Run Application
}
Suthish NairRank #92 · 22.8K reputationPosted Apr 15, 2011, 8:44 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Apr 18, 2011, 10:08 AM EDT
Ankit NandekarRank #703 · 3.4K reputationPosted Apr 19, 2011, 9:03 PM EDT
FileUpload.Saveas(Server.Mappath("newfolder"+filename)) in this code we are saving uploded file into newfolder which is in our root directory of project.Because Server.Mappath Method Pointing to root directory.
If it is useful for u than mark as a accepted answer.