Fck Editor upload images - c#

I have a problem with images in FCK editor. when i try to upload images it gives me Connector disabled error and the images are not showing in the editor page. i am programming with visual studio 2008. please help

Have a look at the following code:
private bool CheckAuthentication()
{
// WARNING : DO NOT simply return "true". By doing so, you are allowing
// "anyone" to upload and list the files in your server. You must implement
// some kind of session validation here. Even something very simple as...
//
// return ( Session[ "IsAuthorized" ] != null && (bool)Session[ "IsAuthorized" ] == true );
//
// ... where Session[ "IsAuthorized" ] is set to "true" as soon as the
// user logs in your system.
MembershipUser m = Membership.GetUser();
if (m != null)
{
return true;
} else {
return false;
}
//return false;
}
Then update both App and Root files.

Related

Indexing content that is attached to some page

I have this requirment to only index that data, for searching, which is being used in some page. For example if I upload a document it shouldn't be available for search until I use it in some page. I found out this code online
ContentIndexer.Instance.Conventions.ForInstancesOf().ShouldIndex(x =>
{
var contentRepository =
EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance();
var contentSoftLinkRepository =
EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance();
var softLinks = contentSoftLinkRepository.Load(x.ContentLink, true);
try
{
foreach (var softLink in softLinks)
{
if (softLink.SoftLinkType == ReferenceType.ExternalReference ||
softLink.SoftLinkType == ReferenceType.ImageReference)
{
var content =
contentRepository.Get(softLink.OwnerContentLink);
if (!ContentIndexer.Instance.Conventions.ShouldIndexConvention.ShouldIndex(content).Value) // don't index referenced file if content is marked as not indexed
{
continue;
}
// only index if content is published
var publicationStatus =
content.PublishedInLanguage()[softLink.OwnerLanguage.Name];
if (publicationStatus != null &&
(publicationStatus.StartPublish == null ||
publicationStatus.StartPublish < DateTime.Now) &&
(publicationStatus.StopPublish == null ||
DateTime.Now < publicationStatus.StopPublish))
{
return true;
}
}
}
}
catch
{
// ooops something went wrong. Better not index this one ;-)
}
return false;
});
This works when I attach softlinks. But lets say a page has a property called Content type and when I add something in there, lets say a block which has softlinks to that document, it doesn't work. I am stuck in there. Any hints?
Do you have a wildcard * host configured on any of your sites?
Check Admin > Manage websites and go through all sites to see if there is a * configured.
Having a wildcard tells Episerver Find to index standalone content (i.e. globalassets) using the site primary URL that contains the wildcard, regardless of it being referenced. If you don't have a wildcard configured, Episerver Find can't index content that are NOT referenced (i.e. globalassets) because it cannot generate a public URL for it. Global assets that are referenced will be indexed using the domain of the site that references it. Hope this helps.

Refresh the data of view after downloading a file in mvc

Have searched for solutions and also tried different things but unable to find solution for this one. So my question is:
I have a form with fields like name,email,contact no for registration. Once i click on the button what i am doing is that i am allowing user to download a file for which i have written the code as below
[HttpPost]
public ActionResult MBA_Programme(mba_programmeViewModel vm)
{
if (vm.mba_Id == null || vm.mba_Id == 0)
{
vm.Created_Date = DateTime.Now;
vm.Created_By = User.Identity.Name.ToString();
admin.addMbaDetail(vm);
if (vm.Flag != null)
{
ModelState.Clear();
return new FilePathResult(Server.MapPath("~/eiclandingpages/EIC-MBA.doc"), "application/msword");
}
else
{
return RedirectToAction("MBA_Programme", "EIC");
}
}
else
{
return RedirectToAction("MBA_Programme", "EIC");
}
}
The issue which i am facing is that once the form is getting downloaded the page is not getting refresh . I tried modelstate.clear() but not able to do it . I tried jquery also for location.reload but it refreshes but file wont downlaod and also refresh with delay.
Kindly help.
p.s: file i am getting from the folder in the project

Unable to do 'add a Button to the Sitecore Content Editor Ribbon to Debug Any Item in Any Database'

I have tried to create a debug button as shown below taking reference from link#3 in bottom, I have compiled and configured the button in core database and configured the Commands.config but I am getting error message on the master database when I click from ribbon and sitecore admin client is restarted. I am not getting what the error message is points to.. !
Ribbon Button screen
Error Message Text
Control "system" does not exist on form. at Sitecore.Shell.Framework.Commands.CommandManager.GetMethodCommand(String command) at Sitecore.Shell.Framework.Commands.CommandManager.GetDispatchCommand(String command) at Sitecore.Web.UI.Sheer.ClientPage.Dispatch(String command) at Sitecore.Web.UI.Sheer.ClientPage.RaiseEvent() at Sitecore.Web.UI.Sheer.ClientPage.OnPreRender(EventArgs e)
Error Message screen
One more thing the link#2 mentioned in the bottom does not seems to contain the 'prototype zip available in the Resources section' as said by John in the blog post here.. can anyone see If I'm not wrong?
PS: link#1 is the old post to the link#2
Debug.cs code
using System;
namespace SitecoreDemo.Shell.Framework.Commands.System
{
[Serializable]
// implements the debug command on the Sitecore menu of the desktop
// and in the ribbon of the Content Editor
public class Debug : Sitecore.Shell.Framework.Commands.System.Debug
{
public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
{
// validate arguments and processing context
Sitecore.Diagnostics.Assert.ArgumentNotNull(context, "context");
Sitecore.Diagnostics.Assert.IsNotNull(Sitecore.Context.ClientPage, "ClientPage");
Sitecore.Diagnostics.Assert.IsNotNull(Sitecore.Context.ClientPage, "ClientResponse");
// ensure the new browser window authenticates as the current CMS user
// (in case the user formerly previewed as another user)
Sitecore.Publishing.PreviewManager.RestoreUser();
// open the new browser window
Sitecore.Web.UI.Sheer.SheerResponse.Eval("window.open('" + this.GetDebuggingUrl(context) + "', '_blank');");
}
// construct a URL to launch the debugger
private string GetDebuggingUrl(Sitecore.Shell.Framework.Commands.CommandContext context)
{
// whether to use the sc_lang query string parameter to specify the language
bool includeLanguage = Sitecore.Links.LinkManager.LanguageEmbedding != Sitecore.Links.LanguageEmbedding.Never;
// URL of the debugging window defaults to home page of managed site
Sitecore.Text.UrlString url = new Sitecore.Text.UrlString("/");
// enable all debugging options
url.Add("sc_debug", "1"); // enable the debugger
url.Add("sc_prof", "1"); // enable profiling
url.Add("sc_trace", "1"); // enable tracing
url.Add("sc_ri", "1"); // enable rendering information
// if the user has selected an item, ensure they have saved,
// then debug the item in the database and language associated with that item
if (context != null && context.Items != null && context.Items.Length > 0 && context.Items[0] != null)
{
Sitecore.Context.ClientPage.ClientResponse.CheckModified(false);
Sitecore.Data.Items.Item item = context.Items[0];
url.Add("sc_database", item.Database.Name);
url.Add("sc_itemid", item.ID.ToString());
if (includeLanguage)
{
url.Add("sc_lang", item.ID.ToString());
}
}
// if the user has not selected an item,
// if there is a content database, debug that database
// using the content language
else if (Sitecore.Context.ContentDatabase != null)
{
url.Add("sc_database", Sitecore.Context.ContentDatabase.Name);
if (includeLanguage)
{
url.Add("sc_lang", Sitecore.Context.ContentLanguage.Name);
}
}
// return a URL to open the debugger
return url.GetUrl();
}
public override Sitecore.Shell.Framework.Commands.CommandState QueryState(Sitecore.Shell.Framework.Commands.CommandContext context)
{
// if the user has selected at least one item
if (context.Items != null && context.Items.Length > 0 && context.Items[0] != null)
{
// if that item does not specify a layout for any device, disable this command
if (!this.HasLayoutForAnyDevice(context.Items[0]))
{
return Sitecore.Shell.Framework.Commands.CommandState.Disabled;
}
}
return base.QueryState(context);
}
// returns true if the item specifies a layout for any device
protected bool HasLayoutForAnyDevice(Sitecore.Data.Items.Item item)
{
Sitecore.Diagnostics.Assert.IsNotNull(item, "item");
// evaluate each device in the database containing the item
foreach (Sitecore.Data.Items.DeviceItem compare in item.Database.Resources.Devices.GetAll())
{
// if the item specifies layout details for that device, return true
if (item.Visualization.GetLayout(compare) != null)
{
return true;
}
}
// layout details for the item do not specify a layout for any device
return false;
}
}
}
Reference links:
Add a Button to the Sitecore Content Editor Ribbon to Debug Any Item in Any Database
Update: Add Debug Command to Content Editor in the Sitecore ASP.NET CMS
Professional Sitecore Development- Google Books
The prototype link has a zip file and contains the Debug.cs file.
Code below
using System;
namespace Sitecore.Sharedsource.Shell.Framework.Commands.System
{
[Serializable]
public class Debug : Sitecore.Shell.Framework.Commands.Command
{
public override void Execute(
Sitecore.Shell.Framework.Commands.CommandContext context)
{
Context.ClientPage.ClientResponse.CheckModified(false);
Sitecore.Data.Database contentDatabase = Context.ContentDatabase;
if ((context.Items != null) && (context.Items.Length == 1))
{
Sitecore.Data.Database database = context.Items[0].Database;
}
Sitecore.Text.UrlString webSiteUrl =
Sitecore.Sites.SiteContext.GetWebSiteUrl();
webSiteUrl.Add("sc_debug", "1");
if ((context.Items != null) && (context.Items.Length == 1))
{
Sitecore.Data.Items.Item item = context.Items[0];
if (item.Visualization.Layout != null)
{
webSiteUrl.Add("sc_itemid", item.ID.ToString());
}
webSiteUrl.Add("sc_lang", item.Language.ToString());
}
if (contentDatabase != null)
{
webSiteUrl.Add("sc_database", contentDatabase.Name);
}
webSiteUrl.Add("sc_prof", "1");
webSiteUrl.Add("sc_trace", "1");
webSiteUrl.Add("sc_ri", "1");
Context.ClientPage.ClientResponse.Eval(
"window.open('" + webSiteUrl + "', '_blank')");
}
}
}
Let me know if this code helps you and will get back to you if I find any more information.
The provided solution prototype at here on the blog post Update: Add Debug Command to Content Editor in the Sitecore ASP.NET CMS solved my issue, I have configured my own Debug.cs class file in the command and copied the Debug.item file from the solution prototype zip to folder location as specified in the post (and also mentioned below) and it is working now.
For references in future check below the steps as shown on the blog post to configure the solution prototype that helped me.
To create the command definition item using the serialization file:
Copy the Debug.item file from the prototype zip available in the
Resources section at the end of this blog post to the
/data/serialization/core/sitecore/content/Applications/Content
Editor/Ribbons/Chunks/Publish subdirectory of your Sitecore
solution, where the /data folder is typically a sibling of the
Website folder.
Log into the Sitecore desktop as an administrator.
Click the database icon in the lower right corner and then select
Core from the menu that appears (as described in the Sitecore Client
Configuration Cookbook).
Open the Content Editor, navigate to the
/sitecore/content/Applications/Content Editor/Ribbons/Chunks/Publish
item (copy that path to your clipboard, paste it into the search box
above the content tree, press Enter, select the first result).
On the Developer tab, in the Serialize group, click Revert Tree. If
you right-click the /sitecore/content/Applications/Content
Editor/Ribbons/Chunks/Publish item in the content tree and then
click Refresh from the submenu that appears, a new Debug item should
appear.
Remember to use the database icon to select the Master
database.
PS: However when I had created the debug item myself in content editor from core database it was not working don't know why.

Use ASP.Net MVC only for mobile clients

We currently have a large ASP.Net webforms website , and we just started converting some parts of it to asp.net MVc
We want to create a version of the site specifically for mobile clients, and we would like to start off using MVC for that.
I know that MVC supports by convention that views files ending in .mobile are served for mobile clients. But my question is - how would i set things up in general that desktop clients still use default.aspx but that mobile clients get redirected to /home
The code for browser detection should be put in a base class that all your pages will derive from. Try below code:
protected void Page_Load(object sender, EventArgs e)
{
if (IsMobileBrowser())
{
Response.Redirect("/home");
return;
}
// your other code
}
public static bool IsMobileBrowser()
{
//GETS THE CURRENT USER CONTEXT
HttpContext context = HttpContext.Current;
//FIRST TRY BUILT IN ASP.NT CHECK
if (context.Request.Browser.IsMobileDevice)
{
return true;
}
//THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER
if (context.Request.ServerVariables["HTTP_X_WAP_PROFILE"] != null)
{
return true;
}
//THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP
if (context.Request.ServerVariables["HTTP_ACCEPT"] != null &&
context.Request.ServerVariables["HTTP_ACCEPT"].ToLower().Contains("wap"))
{
return true;
}
//AND FINALLY CHECK THE HTTP_USER_AGENT
//HEADER VARIABLE FOR ANY ONE OF THE FOLLOWING
if (context.Request.ServerVariables["HTTP_USER_AGENT"] != null)
{
//Create a list of all mobile types
string[] mobiles =new[]
{
"midp", "j2me", "avant", "docomo",
"novarra", "palmos", "palmsource",
"240x320", "opwv", "chtml",
"pda", "windows ce", "mmp/",
"blackberry", "mib/", "symbian",
"wireless", "nokia", "hand", "mobi",
"phone", "cdm", "up.b", "audio",
"SIE-", "SEC-", "samsung", "HTC",
"mot-", "mitsu", "sagem", "sony"
, "alcatel", "lg", "eric", "vx",
"NEC", "philips", "mmm", "xx",
"panasonic", "sharp", "wap", "sch",
"rover", "pocket", "benq", "java",
"pt", "pg", "vox", "amoi",
"bird", "compal", "kg", "voda",
"sany", "kdd", "dbt", "sendo",
"sgh", "gradi", "jb", "dddi",
"moto", "iphone"
};
//Loop through each item in the list created above
//and check if the header contains that text
foreach (string s in mobiles)
{
if(context.Request.ServerVariables["HTTP_USER_AGENT"].ToLower().Contains(s.ToLower()))
{
return true;
}
}
}
return false;
}
See more at:
http://www.codeproject.com/Articles/213825/ASP-net-Mobile-device-detection
http://www.codeproject.com/Articles/34422/Detecting-a-mobile-browser-in-ASP-NET
try like this
if (request.Browser.IsMobileDevice)
{
//rediret the user to mobile views
}
make sure you remove webform View Engine. like this. MobileCompatibleViewEngine
ViewEngines.Engines.Remove(ViewEngines.Engines.OfType<WebFormViewEngine>().First());
ViewEngines.Engines.Add(new MobileCapableWebFormViewEngine()); // this will come from Nuget Package.
Write the below code in to Global.asax.
If user will access the website through Desktop it will automatically redirect to Desktop website weather user access through Android phone it will
automatically redirect to mobile website
protected void Application_Start()
{
DisplayModes.Modes.Insert(0, new DefaultDisplayMode("Android")
{
ContextCondition = (context => context.Request.UserAgent.IndexOf
("Android", StringComparison.OrdinalIgnoreCase) >= 0)
});
DisplayModes.Modes.Insert(0, new DefaultDisplayMode("WindowsPhone")
{
ContextCondition = (context => context.Request.UserAgent.IndexOf
("Windows Phone OS", StringComparison.OrdinalIgnoreCase) >= 0)
});
}

Determine display mode of sharepoint page

I have this question many times and bored while trying to find good solution.
Dont understand why microsoft not include method which can easy determine mode of display page: "normal display" or in "design mode".
It have many advices of check different variables, but it cant uniquely say that page in design on different type of page(webpart page and wiki page) and on postback or not.
Is finally tired me and i write this:
public static bool IsDesignTime()
{
if (SPContext.Current.IsDesignTime) return true;
if (HttpContext.Current.Request.QueryString["DisplayMode"] != null)
return true;
var page = HttpContext.Current.Handler as Page;
if(page == null) return false;
var inDesign = page.Request.Form["MSOLayout_InDesignMode"];
var dispMode = page.Request.Form["MSOSPWebPartManager_DisplayModeName"];
var wikiMode = page.Request.Form["_wikiPageMode"];
var we = page.Request.Form["ctl00$PlaceHolderMain$btnWikiEdit"];
if (inDesign == null & dispMode == null) return false; //normal display
if (we == "edit") return true; //design on wiki pages
if (page is WikiEditPage & page.IsPostBack & inDesign == "" & dispMode == "Browse" & wikiMode == "") return false; //display wiki on postback
if (inDesign == "" & dispMode == "Browse" & (wikiMode == null | wikiMode == "")) return false; //postback in webpart pages in display mode
if (inDesign == "0" & dispMode == "Browse") return false; //exiting design on webpart pages
return true;
}
Does anybody have better solution?
you have 2 case to detect the page mode:
In case you are using a team site :
if (Microsoft.SharePoint.SPContext.Current.FormContext.FormMode == SPControlMode.Edit)
{
ltr.Text = "EditMode2";
}
else
{
ltr.Text = "ViewMode";
}
in case you are using a publishing site:
if (Microsoft.SharePoint.SPContext.Current.FormContext.FormMode == SPControlMode.Display)
{
// your code to support display mode
}
else // Microsoft.SharePoint.SPContext.Current.FormContext.FormMode = SPControlMode.Edit
{
// your code to support edit mode
}
if your work in WebpartPage than below code work for me
WebPartManager mgr = this.WebPartManager;
if (mgr.DisplayMode == WebPartManager.EditDisplayMode)
{
// logic when in Edit Mode
}
else
{
}
I had a hard time getting any of these answers to work in Sharepoint 2013 given all the scenarios. I also couldn't get EditModePanel to work consistently. I found a snippet in this article that seems to work in every scenario I've tried so far.
Note: This does not work in Page_Init but will work in Page_Load
var isPublishing = SPContext.Current.FormContext.FormMode != SPControlMode.Invalid;
var wpDMode = WebPartManager.GetCurrentWebPartManager(Page).DisplayMode.Name;
var isEditing = isPublishing
? SPContext.Current.FormContext.FormMode != SPControlMode.Display
: (wpDMode.Equals("Edit") || wpDMode.Equals("Design"));
Then you can simply check isEditing for your conditions.
please try this code ..
if (Microsoft.SharePoint.SPContext.Current.FormContext.FormMode == SPControlMode.Display)
{
// your code to support display mode
}
else // Microsoft.SharePoint.SPContext.Current.FormContext.FormMode = SPControlMode.Edit
{
// your code to support edit mode
}
Handling SharePoint Page Modes.
This works for me , I resolved my critical issue by using below lines.
if (Microsoft.SharePoint.SPContext.Current.FormContext.FormMode == SPControlMode.Edit)
{
alert.Text = "EditMode2";
}
else
{
alert.Text = "ViewMode";
}

Categories