$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>File Upload using Twitter Bootstrap, C#, asp.net and javascript - Stack Overflow|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

File Upload using Twitter Bootstrap, C#, asp.net and javascript - Stack Overflow

matteradmin15PV0评论

link to Jasny .html#fileupload

link to what the form looks like .png

I am using the Jasny Javascript file upload in my boot strap project, it looks like this:

ASP\HTML VIEW

<div class="row-fluid">
<div class="fileupload fileupload-new" data-provides="fileupload"><input type="hidden">
<div class="input-append">
<div class="uneditable-input span2" runat="server" id="statment1"><i class="icon-file  
fileupload-exists"></i> <span class="fileupload-preview" style=""></span></div><span 
class="btn btn-file"><span class="fileupload-new">Select file</span><span 
class="fileupload-exists">Change</span><input type="file"></span><a href="#" class="btn 
fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>
</div>

How do I go about using this in the code behind to save the attached file to my server as I would using the C# asp File Upload?

In ASP C# I would normally do this in the code behind:

ASP C# CodeBehind

string filename = FileUpload1.PostedFile.FileName;
FileUpload1.PostedFile.SaveAs(Path.Combine(Server.MapPath("\\Document"), 
filename).ToString());
                filelocation = "Document\\" + filename;
                media = "Document";

The Jasny github explains how to set the layout using bootstrap which is great as it looks really good (much better than the boring asp file upload) but How do I actually get I to post on my button click? I would really like to get this to work as I think it looks heaps nicer.

link to Jasny http://jasny.github./bootstrap/javascript.html#fileupload

link to what the form looks like http://img507.imageshack.us/img507/3308/picpx.png

I am using the Jasny Javascript file upload in my boot strap project, it looks like this:

ASP\HTML VIEW

<div class="row-fluid">
<div class="fileupload fileupload-new" data-provides="fileupload"><input type="hidden">
<div class="input-append">
<div class="uneditable-input span2" runat="server" id="statment1"><i class="icon-file  
fileupload-exists"></i> <span class="fileupload-preview" style=""></span></div><span 
class="btn btn-file"><span class="fileupload-new">Select file</span><span 
class="fileupload-exists">Change</span><input type="file"></span><a href="#" class="btn 
fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>
</div>

How do I go about using this in the code behind to save the attached file to my server as I would using the C# asp File Upload?

In ASP C# I would normally do this in the code behind:

ASP C# CodeBehind

string filename = FileUpload1.PostedFile.FileName;
FileUpload1.PostedFile.SaveAs(Path.Combine(Server.MapPath("\\Document"), 
filename).ToString());
                filelocation = "Document\\" + filename;
                media = "Document";

The Jasny github explains how to set the layout using bootstrap which is great as it looks really good (much better than the boring asp file upload) but How do I actually get I to post on my button click? I would really like to get this to work as I think it looks heaps nicer.

Share Improve this question edited Jul 4, 2013 at 15:48 Magnus Johansson 28.3k19 gold badges109 silver badges169 bronze badges asked Aug 27, 2012 at 2:12 AudoAudo 1351 gold badge2 silver badges7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

Since you want to do this without a standard asp control, you will have to do some of the wiring that asp does for you.

Make sure your input has an id. I will set it here to myFile.

<div class="row-fluid">
    <div class="fileupload fileupload-new" data-provides="fileupload"><input type="hidden">
        <div class="input-append">
            <div class="uneditable-input span2" runat="server" id="statment1">
                <i class="icon-file fileupload-exists"></i> 
                <span class="fileupload-preview" style=""></span>
            </div>
            <span class="btn btn-file"><span class="fileupload-new">Select file</span>
            <span class="fileupload-exists">Change</span><input id="myFile" type="file" runat="server">
            </span>
            <a href="#" class="btn fileupload-exists" data-dismiss="fileupload" >Remove</a>
        </div>
    </div>
</div>

Your page should now have a HtmlInputFile control to your page. like this:

protected HtmlInputFile myFile;

Then you should be able to receive the file:

if (IsPostBack)
{
    if (myFile.PostedFile != null)
    {
        // File was sent
        var postedFile = myFile.PostedFile;
        int dataLength = postedFile.ContentLength;
        byte[] myData = new byte[dataLength];
        postedFile.InputStream.Read(myData, 0, dataLength);
    }
    else
    {
        // No file was sent

    }
}
Post a comment

comment list (0)

  1. No comments so far