Following is the HTML form code, for uploading text value and a JPEG file.
<html>
<head></head>
<body>
<form action="https://mywebsiteforexample.com/" method="post" enctype="multipart/form-data">
<input type="text" name="id" value="01"/>
<input type="file" name="image">
<input type="submit" value="send">
</form>
</body>
</html>
Problem is whenever I have to upload the file on server, I need to manually browse the file to upload it. I want to write the same code in C# so when I run the code it itself select the file by path given, and upload the file so I don't need to browse and select the file manually. Is it possible.
You don't need to write code that fills input elements (if you want, use Selenium with C# driver). Just simulate POST action from simple console application using for e.g. HttpClient.
There are plenty of questions on SO how to do it, e.g. C# HttpClient 4.5 multipart/form-data upload
Related
I have a <form> where I am using Vue.js and Quasar, and submits in as a HTML form in asp .net core 3.1
The problem is when I am using Quasar Uploader (https://quasar.dev/vue-components/uploader).
The functionality works fine, but when I submit the form (post i C# and .net core).
I cant get the the file in the controller.
As you can see from this example: https://codepen.io/cbrown___/pen/GRZwpxw
When the Uploader is rendered it does not have the attribute name. From the example above you have this input:
<input tabindex="-1" type="file" title="" class="q-uploader__input overflow-hidden absolute-full">.
I guess that is why I cant get it from my Controller. How can I solve this when I am using .net Core 3.1 to submit this form?
And I see no good solutinos in letting people upload files through my API before the record is created.
Is it a option here I do not see?
EDIT:
The <input> is on the plus-icon. So by using inspect elements you should be able to see that no name occurs.
EXAMPLE CODE:
HTML
<div id="q-app">
<div class="q-pa-md">
<div class="q-gutter-sm row items-start">
<q-uploader
url="http://localhost:4444/upload"
style="max-width: 300px"
></q-uploader>
<q-uploader
url="http://localhost:4444/upload"
color="teal"
flat
bordered
style="max-width: 300px"
></q-uploader>
<q-uploader
url="http://localhost:4444/upload"
label="Upload files"
color="purple"
square
flat
bordered
style="max-width: 300px"
></q-uploader>
<q-uploader
url="http://localhost:4444/upload"
label="No thumbnails"
color="amber"
text-color="black"
no-thumbnails
style="max-width: 300px"
></q-uploader>
</div>
</div>
</div>
JS:
new Vue({
el: '#q-app'
})
If any body else need this I ended up with using this:
:name="'file_description[' + index + ']'"
That way each one got one name...and from another array I knew how many file_description it would be.
There is a HTML code, in another website :
<form action="down.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="mid" id="mid" value="pg/K/c3scJubYvZj8UI=" />
<span><input class="btnff" type="submit" value="downloadd" /></span>
</form>
I want to download with Watin and c sharp :
WatiN.Core.Button btn1 = browser1.Button(Find.ByValue("downloadd")) as WatiN.Core.Button;
btn1.Click();
When I click on it, download start with IDM(Internet download manager).
The Link does not exist in Source code, even after I click on Button.
How can I get Link with Watin(Not IDM) and download with c sharp to save in a specific folder?
I am trying to login into fogbugz using my c# application.I am using FogBugz XML API.
The code that I am currently using is:
<form method="post" action="https://xxxxx.fogbugz.com/api.asp?cmd=logon">
Email:
<input type="text" value="email" name="email">
<br />
Password:
<input type="password" value="password" name="password">
<br />
<input type="submit">
<br />
</form>
When I do this I do get logged into FogBugz.I get an XML file as output where I have my token under tags.
Is there any way to make the user see an aspx file and not the XML file but I could use the XML file and cache the token value?
I am new to FogBugz please help!
Thank you.
I would recommend checking out FogLampz.
It allows you to write code such as:
FogBugzClient.LogOn("https://myproject.fogbugz.com/api.asp",
"email#mydomain.com", "password");
var projects = FogBugzClient.GetProjects();
var areas = FogBugzClient.GetAreas();
Use this in your code-behind for your aspx page. (you wont need your form action pointing to fogbugz)
You can then display/modify/do-anything-to the results as you wish.
Alternatively there is the Fogbugz Csharp API Wrapper which allows very similar coding style to pull out FogBugz data.
i can't find anywhere how can i get selected file's path in asp.net mvc (i am using c#)?
I need to send file to server, so i just need to get it's path and then i use
Image image = Image.FromFile(path);
but only way to get path i found was:
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
but i dont want to save my file. If i use
Path.GetFullPath
i get path in II Express folder and i can not use this path.
So, is there any way to get selected file's path?
How select file:
<form id="Form1" method="post" enctype="multipart/form-data" runat="server">
<input type=file id=File1 name=file value="Browse" runat="server" dir="rtl" aria-selected="false" />
<br>
<input type="submit" id="Submit1" value="Upload" runat="server" aria-haspopup="False" dir="rtl" />
It seems like you're trying to get the file's path on the client, and "read" it to an image object - that's impossible, because the server doesn't have access to the client's filesystem.
Normally, a file upload will look like this:
<form id="form1" runat="server" method="post" enctype="multipart/form-data">
<div>
<input id="File1" type="file" runat="server" />
<input type="submit" value="submit" runat="server" onserverclick="Btn1_ServerClick" />
</div>
</form>
and the server side is:
protected void Btn1_ServerClick(object sender, EventArgs e)
{
var file = File1.PostedFile;
var image = System.Drawing.Image.FromStream(file.InputStream);
}
This is in classic ASP.NET, but if you're using MVC.NET and accessing a controller action it's pretty similar (the controller will receive some sort of HttpPostedFileBase as a parameter from the form)
It is proper behavior of the server and framework that you receive path to location on server.
Normally when we mean one way communication from client to server, as it occurs with http requests (e.g. get or post), the server has not access to clients' file system (hard disk etc). Normally uploading data to server (file) by choosing file on client's file system is sending the data (copy of the file), not path to the file. Server does not initiate getting the file form client by using client's path to it.
I am trying to integrate 3D Secure to my customer's e-shop.
I need to post some data to 3DGate and get the returned result from it.
I have used WebRequest for this, i have posted the data successfuly but the returned data is an Html Text which has a form in it and some inputs in the form. I need to read these values like Request.Form.Get("HashParams") but because of being just a string i couldn't do it.
Is there any way that i can get these form values.
I am doing this WebRequest in the btnPayment_Click Event
Thanks
I believe madcolor is thinking of a different scenario; you're making a completely new webrequest on the server, which means there are no request parameters; you're dealing with a response. Esentially, you've become the web browser, and you have to do the parsing yourself.
Since the e-store you're using is an app that's designed for browsers, you'll have to deal with the limitations inherent to that format. You're esentially bound to "screen scraping" techniques, because the server doesn't see the text from the response as anything other than that: plain text.
If you're dealing with valid XHTML, you can load it into an XmlDocument, and use XPath/XQuery to pull out the values.
If you're dealing with standard crappy HTML, you're going to have to resort to some parsing; I'd suggest a regex for this one.
Ideally, there would be a non-HTML based version of the e-shop, so you would know you were working with valid XML/JSON/whatever, but if there is no alternative, you're stuck ripping the data out yourself.
I can't see a way around having to parse the HTML that comes back from the WebRequest. If you're lucky it might be valid XML. Otherwise you'll have to do your own string parsing or use one of the other HTML parsers.
This is the returned data...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- gateerr_en.htm -->
<html>
<head>
<script type="text/javascript" language="javascript">
function moveWindow() {
document.returnform.submit();
}
</script>
</head>
<body onLoad="javascript:moveWindow()">
<form action="urlHere" method="post" name="returnform">
<input type="hidden" name="clientid" value="xxx">
<input type="hidden" name="oid" value="">
<input type="hidden" name="mdStatus" value="7">
<input type="hidden" name="mdErrorMsg" value="Tanimlanamayan">
<input type="hidden" name="ErrMsg" value="Tanimlanamayan">
<input type="hidden" name="Response" value="Error">
<input type="hidden" name="ProcReturnCode" value="99">
<!-- To support javascript unaware/disabled browsers -->
<noscript>
<center>
An Error Occurred, Please Click to continue.<br>
<input type="submit" value="Submit"></center>
</noscript>
</form>
</body>
</html>
I need to get those hidden inputs