asp.net - Why I can't get selected file on server side? -
i have asp code:
<asp:panel runat="server"> <div class="row2"> <input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" id="fileselect" name="fileselect" runat="server" /> <asp:button id="btnupload" runat="server" text="load" onclick="btnupload_click2" causesvalidation="false" /> </div> </asp:panel>
here generated html code on browser:
<div class="row2"> <input name="ctl00$contentplace$fileselect" type="file" id="ctl00_contentplace_fileselect" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"> <input type="submit" name="ctl00$contentplace$btnupload" value="load" id="ctl00_contentplace_btnupload"> </div> </div>
here code behind:
protected void btnupload_click2(object sender, eventargs e) { httppostedfile file = request.files["fileselect"]; }
after select file of input file element btnupload pressed code behind fired file value null.
if change row:
httppostedfile file = request.files["fileselect"];
to row:
httppostedfile file = request.files["ctl00$contentplace$fileselect"];
i selected file in file variable on server.
so question why can't file if use row:
httppostedfile file = request.files["fileselect"];
your input control runs @ server side, change id, , name posted need use uniqueid
as
httppostedfile file = request.files[fileselect.uniqueid];
where in case fileselect.uniqueid
return "ctl00$contentplace$fileselect"
nane
rendered control on html, 1 used on post.
you can see accessing control client name , not id in asp.net
how use type
to use line
httppostedfile file = request.files["fileselect"];
just remove runat="server"
input control.
Comments
Post a Comment