I'm trying to load a kml on a google map but I cant do it. I'm loading the kml after a click event, and then I call to a function which contains the url:
function LoadRoute(latlng, param1, param2, param3) {
var georssLayer = new google.maps.KmlLayer('http://myserver.net/kmls/file.asp?id='+param1+'&date='+param2+' 00:00:00&EndDate='+param3+' 23:59:59');
georssLayer.setMap(map);
}
The above code doesnt load the kml, but In other hand if I load the same file downloaded directly it works, I mean, like this:
function LoadRoute(latlng, param1, param2, param3) {
var georssLayer = new google.maps.KmlLayer('http://myserver.net/kmls/file.kml');
georssLayer.setMap(map);
}
Does anyone knows what happen? I think it is about the parameters syntax. Anyway if I create another function containing the above url to check if it can be accessed by an url, it works too. For checking it, I open a new tab window to see if the url is well formed, and the result is that the file is donwloaded.
function open_in_new_tab(latlng, param1, param2, param3)
{
window.open('http://myserver.net/kmls/file.asp?id='+param1+'&date='+param2+' 00:00:00&EndDate='+param3+' 23:59:59', '_blank');
window.focus();
}
You have spaces in your URL:
var georssLayer = new google.maps.KmlLayer('http://myserver.net/kmls/file.asp?id='+param1+'&date='+param2+' 00:00:00&EndDate='+param3+' 23:59:59');
That means it needs to be urlencoded
In javascript you can URL encode strings with escape
Related
function IfModuleSucceded(sender, args) {
var existingCount = existingItems.get_count();
var existEnumerator = existingItems.getEnumerator();
while (existEnumerator.moveNext()) {
var currentmodule = existEnumerator.get_current();
var URL = currentmodule.get_item("Request_URL");
alert(URL);
}
}
In this Code i am trying to Retrieve the url of a Hyperlink column which is in a SharePoint list, using Client object model, but i have received an object. How could i get the Url out of this received object ????
when this code is executed, it gives the alert as "[Object Object]".
would anyone help me to sort this out ??
The answer will be alert(url.url) as it's an object.
It will also have a property called description
The Hyperlink field has two properties: Description and Url.
You can access the properties like this: ObjectName.PropertyName
So for your URL object in your example, you can reach the properties like this: URL.Url and URL.Description
I found that Url and Description are case sensitive, so make sure you capitalize where necessary.
This worked great for me.
i am using jquery grid in MVC 3 .as a formatter option i am using following code as a script segment.
function viewformateadorLink(cellvalue, options, rowObject) {
return "" + cellvalue + "";
}
but i don't want to use href here .better option i have found is as follows:
func....(){
var url = '#Html.ActionLink( "_name_", "Edit", new { id = "_id_" })';
url = url.replace(/_name_/, cellvalue);
url = url.replace(/_id_/, rowObject[0]);
return url;
}
are there any simple way exist for passing parameter?
If the value you want to pass to the link is in a JavaScript variable and you don't want to use href, then I'm afraid you can't go further than you already have gone and this is why:
The JavaScript code is ALWAYS executed after the server-side code.
I imagine you would like to do something like:
#Html.ActionLink( "_name_", "Edit", new { id = *JAVASCRIPT VARIABLE* })
but due to the reason I mentioned above, such thing is impossible.
I would suggest you stick to any of the other methods you used in your question.
I have a controller with action:
[HttpPost]
public ActionResult Add(Question container, HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var clientPath=Path.GetDirectoryName(file.FileName);
and clientpath is "".
I need this because I don't want to save file at my server, but right away sending it to flickr
string photoId = flickr.UploadPicture(clientPath, title, description, "", uploadAsPublic, false, false);
How can I get path of client file?
I'm using FlickrNet library btw.
To send the file directly without first saving it on the server, just use the overloaded method:
string photoId = flickr.UploadPicture(file.InputStream, title, description, "", uploadAsPublic, false, false);
You say you want to send the file directly to Flickr but your code attempts to use the clientpath for this... even if it wasn't empty (which it is because of security!) your code would NOT work... because it would try to use a path which only exists on the client-side of your ASP.NET-app as if it were a path on your server...
What you attempt is AFAIK impossible - what is possible is this:
IF FlickrNet library provides an UploadPicture method accepting a Stream then you can call it with file.InputStream... IF it does not provide such an overload you will have to save the file locally on your server in order to upload it to Flickr!
This should be trivial, and I'm pretty sure I did it once before.
I'm trying to post data up to a server and have it bounced back to me as a file download, prompting the native browser file download box. I know the server part works just fine becasue I can post from a demo web form, but when I run the following Flex 3 code, I can't even get the request to fire.
var fileRef:FileReference = new FileReference();
private function saveXmlAsFile(event:MouseEvent):void
{
var fileRequest:URLRequest = new URLRequest();
fileRequest.method = URLRequestMethod.POST;
fileRequest.url = "http://foo.com/dataBounce";
var urlVariables:URLVariables = new URLVariables();
urlVariables.content = "Test content to return" ;
// fileRequest.contentType = "application/x-www-form-urlencoded ";
urlVariables.fileName = "test.xml";
fileRef.addEventListener(SecurityEvent.ALL, onSecurityError);
fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError2);
fileRef.addEventListener(IOErrorEvent.NETWORK_ERROR, onNetworkError);
fileRef.addEventListener(Event.COMPLETE, onComplete);
try
{
fileRef.download(fileRequest, "test.xml");
}catch(error:Error) {
model.logger.error("unable to download file");
}
}
Note, when the call to fileRef.download is called, I can't see any request being made across the network using the traditional Firebug or HTTPWatch browser tools.
EDIT: I should add that this is for < Flash Player 10, so I can't use the newer direct save as file functionality.
Any suggestions? Thanks.
You need to add fileRef.upload to trigger the upload.
Also I would move the download statement to the onComplete so the file isn't requested before it's been uploaded.
Your explanation is pretty clear, but when I look at your code, I'm feel like I'm missing something.
The code looks like you're trying to do half of the upload part and half of the download part.
I think the code you currently have posted would work to trigger a download if you set the .method value to GET. I believe you will also need to include the filename as part of the .url property.
However, to post something and then trigger a download of it, you need two separate operations - the operation to post the data and then an operation to download it, which should probably be called from the upload operation's onComplete handler.
OK, I believe I figured out one of the things that's going on.
When you don't set the URLRequest.data property, it defaults the request method to "GET".
So, the working code looks like, with the data set to the posted URL variables:
private var fileRef:FileReference;
private function saveRawHierarchy(event:MouseEvent):void
{
var fileRequest:URLRequest = new URLRequest();
fileRequest.method = URLRequestMethod.POST;
fileRequest.url = "http://foo/bounceback";
var urlVariables:URLVariables = new URLVariables();
urlVariables.content = "CONTENT HERE";
urlVariables.fileName = "newFileName.xml";
fileRequest.data = urlVariables;
fileRef = new FileReference();
fileRef.addEventListener(Event.COMPLETE, onComplete);
try
{
fileRef.download(fileRequest, "appHierarchies.xml");
}catch(error:Error) {
model.logger.error("unable to download file");
}
}
Not sure what was wrong about the request not being made before, though.
If the controller action has the OutputCache attribute specified on an action, is there any way to clear the output cache without having to restart IIS?
[OutputCache (Duration=3600,VaryByParam="param1;param2")]
public string AjaxHtmlOutputMethod(string param1, string param2)
{
var someModel = SomeModel.Find( param1, param2 );
//set up ViewData
...
return RenderToString( "ViewName", someModel );
}
I'm looking at using HttpResponse.RemoveOutputCacheItem(string path) to clear it, but I'm having trouble figuring out what the path should be to map it to the action method. I'm going to try again with the aspx page that is rendered by ViewName.
Possibly I'll just manually insert the output of RenderToString into the HttpContext.Cache instead if I can't figure this one out.
Update
Please note that the OutputCache is VaryByParam, and testing out a hardcoded path "/controller/action" does not actually clear the outputcache, so it looks like it has to match "/controller/action/param1/param2".
That means I'll probably have to revert to object level caching and manually cache the output for RenderToString() :(
Try this
var urlToRemove = Url.Action("AjaxHtmlOutputMethod", "Controller");
HttpResponse.RemoveOutputCacheItem(urlToRemove);
UPDATED:
var requestContext = new System.Web.Routing.RequestContext(
new HttpContextWrapper(System.Web.HttpContext.Current),
new System.Web.Routing.RouteData());
var Url = new System.Web.Mvc.UrlHelper(requestContext);
UPDATED:
Try this:
[OutputCache(Location= System.Web.UI.OutputCacheLocation.Server, Duration=3600,VaryByParam="param1;param2")]
Otherwise the cache deletion won't work because you've
cached the HTML output on the user's machine
Further to the accepted answer, to support VaryByParam parameters:
[OutputCache (Duration=3600, VaryByParam="param1;param2", Location = OutputCacheLocation.Server)]
public string AjaxHtmlOutputMethod(string param1, string param2)
{
object routeValues = new { param1 = param1, param2 = param2 };
string url = Url.Action("AjaxHtmlOutputMethod", "Controller", routeValues);
Response.RemoveOutputCacheItem(url);
}
However Egor's answer is much better, because it supports all OutputCacheLocation values:
[OutputCache (Duration=3600, VaryByParam="param1;param2")]
public string AjaxHtmlOutputMethod(string param1, string param2)
{
if (error)
{
Response.Cache.SetNoStore();
Response.Cache.SetNoServerCaching();
}
}
When SetNoStore() and SetNoServerCaching() are called, they prevent the current Request being cached. Further requests will be cached, unless the functions are called for those requests as well.
This is ideal for handling error situations - when normally you want to cache responses, but not if they contain error messages.
I think correct flow is:
filterContext.HttpContext.Response.Cache.SetNoStore()
Add code to AjaxHtmlOutputMethod
HttpContext.Cache.Insert("Page", 1);
Response.AddCacheItemDependency("Page");
To clear output cache you can now use
HttpContext.Cache.Remove("Page");
Another option is to use VaryByCustom for the OutputCache and handle the invalidation of certain cache elements there.
Maybe it works for you, but it's not a general solution to your problem