what is worng this my code,
I have 3 fileupload
<table>
<tr>
<td>Provinsi td>
<td><asp:DropDownList ID="cmbprovinsi" runat="server" Height="23px" Width="301px"
onselectedindexchanged="cmbprovinsi_SelectedIndexChanged" AutoPostBack="true">
asp:DropDownList> td>
tr>
<tr>
<td>Kabupaten/Kota td>
<td><asp:DropDownList ID="cmbkabupaten" runat="server" Height="23px"
Width="299px" onselectedindexchanged="cmbkabupaten_SelectedIndexChanged">
asp:DropDownList> td>
tr>
<tr>
<td> Sektor/Bidang td>
<td><asp:DropDownList ID="cmbsektor" runat="server" Height="25px" Width="132px">
asp:DropDownList> td>
tr>
<tr>
<td> Perda Pembentukan td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" class="multi" />
td>
tr>
<tr>
<td> Perda Pengelolaan td>
<td>
<asp:FileUpload ID="FileUpload2" runat="server" />
td>
tr>
<tr>
<td> Perda Retribusi td>
<td>
<asp:FileUpload ID="FileUpload3" runat="server" /> td>
tr>
<tr>
<td>td>
tr>
<tr>
<td>td>
<td>
<asp:Button ID="btnsimpan" runat="server" Text="Simpan"
onclick="btnsimpan_Click" /><asp:Button ID="btnbatal"
runat="server" Text="Batal" /> td>
tr>
table>
protected void btnsimpan_Click(object sender, EventArgs e)
{
// Get the HttpFileCollection
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
string fileName1 = Path.GetFileName(FileUpload1.FileName);
if (hpf.ContentLength > 0)
{
FileUpload1.SaveAs(Server.MapPath("perda_pembentukan") + "\\" +
System.IO.Path.GetFileName(hpf.FileName));
}
string fileName2 = Path.GetFileName(FileUpload2.FileName);
string fileName3 = Path.GetFileName(FileUpload3.FileName);
FileUpload2.SaveAs(Server.MapPath("resource/perda_pengelolaan/") + "\\" +
System.IO.Path.GetFileName(hpf.FileName));
FileUpload3.SaveAs(Server.MapPath("resource/Perda_retribusi/") + "\\" +
System.IO.Path.GetFileName(hpf.FileName));
string Queryinsert = "INSERT INTO tbl_peraturan (propinsi_id,kabupaten_id,sektor_id,namafile1,namafile2,namafile3,perda_pembentukan,perda_pengelolaan,perda_retribusi)" +
" VALUES(@propinsi_id,@kabupaten_id,@sektor_id,@namafile1,@namafile2,@namafile3,@perda_pembentukan,@perda_pengelolaan,@perda_retribusi)";
using (MySqlConnection con = new MySqlConnection(strConnString))
{
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = Queryinsert;
cmd.Parameters.AddWithValue("@propinsi_id", cmbprovinsi.Text);
cmd.Parameters.AddWithValue("@kabupaten_id", cmbkabupaten.Text);
cmd.Parameters.AddWithValue("@sektor_id", cmbsektor.Text);
cmd.Parameters.AddWithValue("@namafile1", fileName1);
cmd.Parameters.AddWithValue("@namafile2", fileName2);
cmd.Parameters.AddWithValue("@namafile3", fileName3);
cmd.Parameters.AddWithValue("@perda_pembentukan", "perda_pembentukan/" + fileName1);
cmd.Parameters.AddWithValue("@perda_pengelolaan", "resource/perda_pengelolaan/" + fileName2);
cmd.Parameters.AddWithValue("@perda_retribusi", "resource/Perda_retribusi/" + fileName3);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
finally
{
con.Close();
}
}
}
}
Loading
hothorasman panjaitanPosted Jan 29, 2015, 12:19 PM
hothorasman panjaitanPosted Jan 27, 2015, 12:22 PM
Jitendra KumarPosted Jan 26, 2015, 6:25 AM
fl 2 have one file
fl 3 have one file ??
Please share code in zip format?
Riddhi ValechaPosted Jan 26, 2015, 6:16 AM
You want to use single File Upload or Multiple File Upload ??
hothorasman panjaitanPosted Jan 26, 2015, 6:05 AM
My previous questions : link
http://www.c-sharpcorner.com/Forums/Thread/283241/
hothorasman panjaitanPosted Jan 26, 2015, 6:02 AM
I want to use 3 FileUpload
fileupload1 my use multi Upload
fileupload2 only one file
fileupload3 only one file
of the code that I created, though more perfect how.?
hothorasman panjaitanPosted Jan 26, 2015, 5:55 AM
Jitendra KumarPosted Jan 26, 2015, 2:15 AM
what problem or issue you are facing in this code.
Abhay ShankerPosted Jan 25, 2015, 10:59 PM