Can I make upload file form in some sandboxed WebPart for Sharepoint Online, and if I can, how can I?
I've searched a lot and found only solutions, available for Client Object Model for outside clients, there is no example how to do this with JSOM (Client Object Model for Javascript) and usual way to upload with asp:FileUpload don't work in sandbox solution, PostedFile length = 0
You do have the option of using the ActiveX STSUpld.UploadCtl control - this enables you to provide the Multi-file upload as you see in a document library.
Note that in the following - Confirmation-URL must be set (where to go when upload is done) and the destination must be set as well to an existing document library.
<script type="text/jscript">
function DocumentUpload() {
var uploadCtl = document.getElementById("idUploadCtl");
uploadCtl.MultipleUpload();
}
</script>
<input type='hidden' name='Confirmation-URL' id='Confirmation-URL' value='' />
<input type='hidden' name='PostURL' id='PostURL' value='' />
<input type="hidden" name="Cmd" value="Save" />
<input type="hidden" name="putopts" value="true" /> <!-- Overwrite files -->
<input type="hidden" name="VTI-GROUP" value="0" />
<input type="hidden" name="destination" id="destination" value="/TestDL" /> <!-- Files destination path, must already exist -->
<p style="margin-left:auto;margin-right:auto;margin-top:0px;margin-bottom:0px;text-align:center;padding:0px !important; vertical-align:top;width:100%;">
<script type="text/javascript">
try {
if (new ActiveXObject("STSUpld.UploadCtl"))
document.write("<OBJECT id=\"idUploadCtl\" name=\"idUploadCtl\" CLASSID=\"CLSID:07B06095-5687-4d13-9E32-12B4259C9813\" WIDTH=\"600px\" HEIGHT=\"250px\" ></OBJECT>");
}
catch (error) {
}
</script>
<asp:Button runat="server" accesskey="O" id="OKButton" CssClass="ms-ButtonHeightWidth" OnPropertyChange="if (this.value != 'Upload files') this.click();" Text="Upload files" UseSubmitBehavior="False" OnClientClick="DocumentUpload(); return false;" />
<asp:Button runat="server" accesskey="C" id="CancelButton" CssClass="ms-ButtonHeightWidth" Text="Cancel" UseSubmitBehavior="False" OnClientClick="window.location ='<somewhere to go>'; return false;" />
Hope this helps....
After some search I finally found solution, based on Codeplex's SPServices. There is plugin SPWidgets(https://github.com/purtuga/SPWidgets/). This plugin loads an iframe with upload.asmx (Sharepoint's default upload form), then set display: none for all elements on this page, exept input[type=file] and adds button, wich can submit form in iframe. After submit plugin catches iframe state (_onIFramePageChange event) and do some callbacks depends on iframe url.
This looks like some ugly workaround, but it is only working solution that I found after hours of search.
There's not too many options, however check out SPServices on CodePlex - this would be the best place to start. Remember - SharePoint expects a binary object when calling the service. You have to capture the file and convert it to binary first, then call the web service to upload.
I have an example but not with me at current location - if the above doesn't get you started, let me know and I will find and post.
Related
Here is the Code in the .aspx web form What is the best way to handle a group of multiple checkboxes.
<input id="nonunionexempt" type="checkbox" value="0" name="employeeType" tabindex="8" runat="server" />
<input id="nonexempthourly" type="checkbox" value="1" name="employeeType" tabindex="9" />
<input id="eleven99" type="checkbox" value="2" name="employeeType" tabindex="10" />
<input id="nysna" type="checkbox" value="3" name="employeeType" tabindex="11" />
<input id="cir" type="checkbox" value="4" name="employeeType" tabindex="12" />
Here is the code behind file Is there a better way to deal with multiple checkboxes?
protected void SaveEmployee()
{
Employee model = new Employee();
if (nonunionexempt.Checked)
{
model.EmployeeType = nonunionexempt.Value;
}
if (nonunionexempt.Checked)
{
model.EmployeeType = nonexempthourly.Value;
}
IValueProvider provider = new FormValueProvider(ModelBindingExecutionContext);
if (TryUpdateModel<Employee>(model, provider))
{
LoaRepository.saveData(model);
}
else
{
throw new FormatException("Could not model bind");
}
}
First, your code sounds good and clean. But if I were you I would use web controls instead of HTML ones. Also, I don't think there is a need to write the if statements even if not using web controls. Simply assign the 'checked' property which is of value true or false. Finally, if embedding the check boxes in a web user control then in the case of multiple usages this could bring a valuable help and of course better maintenance. Hope it helps, good luck!
If you can use the ASP.NET Checkbox control instead of input tags, you won't need the if statements. In code behind use checkBoxID.Checked property which will return true or false.
I have an issue that i believe there is a simple solution for but being new to ASP.NET it is not very clear to me.
I have a user control that has a for loop that makes bunch of hyperlink elements in a list (looks like below>
<li><a href="blahblah.aspx?ID=1..../></li>
<li><a href="blahblah.aspx?ID=2..../></li>
<li><a href="blahblah.aspx?ID=3..../></li>
<li><a href="blahblah.aspx?ID=4..../></li>
Next, that uc is used in another page with in a <form> tag with method="post" and <asp:button> that isn't really used.
Next, when one of the links is clicked it will go to blahblah.asp and get the ID in there via Request.QueryString
So far so good.
What i want to do though (and the reason for this post) is that i want to not use ID as a query parameter. I want to pass the ID in the body. So the link would be blahblah.aspx and it wouldn't show the ID.
What would be the best way to accomplish this. I've tried couple different ways but it's not working.
Not sure if this will work for you, but instead of using html a tags, use the asp LinkButton control. You can then handle the command event of this control so have your for loop generate the following controls (or better yet use a repeater):
<asp:LinkButton id="button1" runat="server" CommandArgument="1" OnCommand="SendToBlah" />
<asp:LinkButton id="button2" runat="server" CommandArgument="2" OnCommand="SendToBlah" />
private void SendToBlah(Object sender, CommandEventArgs e)
{
Session["ID"] = e.CommandArgument;
Response.Redirect("blahblah.aspx");
}
You can then use your session argument inside your blahblah.aspx page however you see fit.
To send the data in the HTTP body instead of the query string, you need to do an HTTP post. This is easy enough, just use a form with a hidden parameter:
<li>
<form action="blahblah.aspx" method="post">
<input type="hidden" name="ID" value="1" />
<input type="submit" value="submit" />
</form>
</li>
To get the data on the target page, use Request.Params instead of QueryString.
Now, if you want to use a hyperlink rather than a "submit" button, you can always submit the form using Javascript:
<li>
<form id="myform1" action="blahblah.aspx" method="post">
<input type="hidden" name="ID" value="1" />
</form>
Submit the form
<form id="myform2" action="blahblah.aspx" method="post">
<input type="hidden" name="ID" value="1" />
</form>
Submit the form
</li>
<script type='text/javascript'>
window.submitForm = function(id) {
document.forms[id].submit();
return false;
}
</script>
I am not a skilled programmer and I am building a site using a third party's CMS. I have created a <form> in order to gather information and send it to an external site. My code doesn't work. The reason I am told is that the site is built on ASP.NET and as the 'master'page already has a <form> element in it and <form> elements cannot be embedded inside one another; so what I've written will never work. I have been advised to look for a java based solution, but I'm at a loss.
My present code is pretty basic...
<form action="http://ExternalWebSite.com" method="post" id="subForm">
<label for="name">Name:</label><br /><input type="text" name="name" id="name" /><br />
<label for="Email">Email Address:</label><br /><input type="text" name="email" id="email" /><br />
<label for="Dog name">Your dog's name:</label><br /><input type="text" name="dogname" id="dogname" /><br />
<label for="Town where you live">Town where you live:</label><br /><input type="text" name="town" id="town" /><br />
<input type="submit" value="Subscribe" />
</form>
How can I make this execute without using the tag inside my html code?
ASP.NET web forms adds one <form runat="server"> in your application. Therefore, you can't nest forms, but you can get multiple forms through a hack, mentioned here.
You can make an ajax call (post in this case) too to that url
$.ajax({
type: "POST",
url: "http://ExternalWebSite.com",
data: { name: $("#name").val(), $("#email").val(), $("#dogname").val(), $("#town").val() },
success: function(result){
//here you handle what to do after the post
}
});
For further reference on how to use jquery go to: This link The most imortant here is the ajax called which is foinf to make a post the specified utl sending the named parameters,the success function which will receive anything you write on the response on the url you are calling, and the selectors $("#name").val() which means "give me the value of the element with the id name"
I am having a signup page at the upper of the page there is a form tag that is runat server. I want to add a code that is given by paypal take payment. That code contains a simple html controls not asp.net controls but when i paste to the code to the page then it don't submit it to the action it postback the form and don't do with paypal code at all. when i checked the source of the code it doesn't shows the from tag given by the paypal. it doesn't rander the form given by the paypal. I also have to take the form at top because my page has asp.net controls that's why that is necessary.
Please tell the solution
You must not use asp.net form tag in asp.net while payment processing.
Use this
<body onload="document.paypal.submit();">
<form name="paypal" action='<%= ConfigurationManager.AppSettings["PayPalSubmitUrl"] %>'
method="post">
// rest html goes here
</form>
</body>
I always do it like this for paypal processing
I assume you are using PayPal Standard.
If so, collect submitted values from (regular ASP.Net) form. Then forward them to PayPal like this -
protected void SubmitRadButton_Click(object sender, EventArgs e)
{
string paypalUrl = IsTestMode ?
"https://www.sandbox.paypal.com/us/cgi-bin/webscr" :
"https://www.paypal.com/us/cgi-bin/webscr";
var builder = new StringBuilder();
builder.Append(paypalUrl);
builder.AppendFormat("?cmd=_xclick&business={0}", EmailTextBox.Text);
builder.Append("&lc=US&no_note=0¤cy_code=USD");
builder.AppendFormat("&item_name={0}", ItemNameHiddenField.Value);
builder.AppendFormat("&amount={0}", AmountTextBox.Text);
builder.AppendFormat("&return={0}", ReturnUrl);
builder.AppendFormat("&cancel_return={0}", CancelUrl);
builder.AppendFormat("&undefined_quantity={0}", 1);
builder.AppendFormat("&item_number={0}", ItemNumberHiddenField.Value);
builder.AppendFormat("&cpp_header_image={0}", HeaderImage);
HttpContext.Current.Response.Redirect(builder.ToString());
}
I tried the same but didn't work. Please see my paypal code that they provided and let me know how to do this. I have tried the above method previously but this time isn't working with code. May be it is for subscription code different. Read the code following and let me know about how to use this.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="LL5LZEB8L6T8S" />
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif"
name="submit" alt="PayPal - The safer, easier way to pay online!" />
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif"
width="1" height="1" />
</form>
Thanks
I have a child page LoginContent.aspx which contains a login form. If the user logs in he should be redirected to my Welcome.aspx page. But if I press the login button the page just reloads itself, nothing happens.
The codebehind on this page is empty. Both LoginContent.aspx and Welcome.aspx are child forms of the same master page.
<form method="post" action="~/Welcome.aspx">
Username: <input type="text" name="username" size="15" /><br />
Password: <input type="password" name="passwort" size="15" /><br />
<input type="submit" value="Login"/></p>
</form>
I know I could use the asp.net login control but I want more control over things.
You can't have nested form inside aspx page.
UPDATED:
Since ASP.NET webform doesn't allow us to have multiple form in one aspx page, thus in order to make it works, do the following:
Remove the form tag
add runat server to
the input perform redirect in the server side
.
Username: <input type="text" name="username" size="15" runat=server /><br/>
Password: <input type="password" name="passwort" size="15" runat=server /><br/>
<input type="submit" value="Login" runat=server onclick="submit_onclick" /></p>
And in the code behind:
protected void submit_onclick(object sender, Event e)
{
// do some auth stuff here
Response.Redirect("~/welcome.aspx");
}
Hope this will answer your question.. :)
If your <form> tag from your LoginContent.aspx nested inside your <form runat="server"> I would try moving it so it sits outside the server-side form and see if it works from there.
It might be worth tracking the HTTP requests in the Net panel of Firebug as well, just so you can see if it is actually making the HTTP POST request to /Welcome.aspx - it might help you pinpoint exactly where the problem is.