Updating Campaign Member using Salesforce API and C#

Web programming
Well, if you check at Salesforce API documentation and follow their tutorial to connect to SF database and request data, everything should be fine. The API its pretty flexible and solid. But, once you get to the update point you may find some problem... I connected to Salesforce and requested my CampaignMember, loading it into an object called "CampaignMember" (yes, im so original). Then, if I tried to update it using something like: [sourcecode language="csharp" wraplines="false"] Salesforce.SaveResult[] saveResults = sf.update(new Salesforce.sObject[] { CampaignMember }); [/sourcecode] It would not work, since it seems that object has every field filled and would try to update all of them, including the read-only ones. So I would receive a saveResults object with the error message "Unable to create/update fields: CampaignId, HasResponded, LeadId. Please check…
Read More

Adding Libraries to your .Net Application Project

Web programming
Some years ago, if you wanted to divide your project with layers having a business and a "data access" layer you could create a special folder in your .Net application called "App_Code". Just doing a right Click on the project and then selecting Add -> .Net Folder -> App_Code. While that helped dividing layers some people found it less reusable since the layers where part of the project in the end, and then it became a good practice to use libraries instead to a point where the folder App_Code has disappeared from Visual Studio and you shouldn't use it anymore. So now, to have your "App_Code" you should use Class Libraries instead. You can create them separately and add them to the project or create them directly inside the project.…
Read More

Embedding images in an Email sent by ASP.Net Server

Web programming
If you want to embed your images in an email sent using ASP.Net server instead than using URLs you can use an AlternateView and use the mime standard to embed them: [sourcecode language="csharp" wraplines="false"] using System.Net.Mail; protected void SendBTN_Click(object sender, EventArgs e) { // Send email using ASP.Net: System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.From = new System.Net.Mail.MailAddress(Email_From); message.To.Add(Email_To); message.Bcc.Add(Email_BCC); message.Subject = Email_Subject; message.IsBodyHtml = true; message.AlternateViews.Add(getS4HRegisteredUsersWithoutAnOrderBody_ForEmail(Customer.Name)); SmtpClient smtp = new SmtpClient("subdom.myserver.com"); smtp.Send(message); // Show some "Email Sent" msg and all that stuff or return ok. } private AlternateView getS4HRegisteredUsersWithoutAnOrderBody_ForEmail(String CustName) { StringBuilder body = new StringBuilder(); body = SkyGuard.MIS.Email.getTemplate("S4HRegisteredUserWithoutOrder.htm"); body.Replace("[SUBJECT]", Email_Subject); body.Replace("[CUSTNAME]", CustName); //These keys are set into the image src attribute body.Replace("[LOGO_IMGSRC]", "cid:logo"); //Notice that we are adding a cid:id as the image source body.Replace("[SUPPORT_PHOTO_IMGSRC]", "cid:avatar"); body.Replace("[SIGNATURE_IMGSRC]", "cid:signature"); AlternateView…
Read More

Mailto: and its parameters

Web standards
Mailto is a link "address" we can set to an anchor tag to let the user send an email to someone with just a click. Something like this: [sourcecode language="html" wraplines="false"] <a href="mailto:[email protected]">Send email</a> [/sourcecode] That would show something like this: Send email If you click on there, and you have configured in your PC a default email software to handle it, Outlook or the software you are using will open with a blank email with just an address at the "To" field, the one written in the link. You can also configure your browser to open your Gmail/hotmail/whatever account when doing this. Now, what if you wanted to send that email with a default subject, cc, bcc or including body? Well you can, just adding parameters as if it…
Read More

How can I force a page jump in HTML printing?

Web programming, Web standards
If you would like to decide when the page will break and the next one will be started when your web page is printed you can use three CSS2.0 styles to set this "jump". page-break-before: Sets the element page break behavoir before the element starts. page-break-inside: Lets you set that the page break behavior has to be avoided inside this element. page-break-after: Sets the element page break behavoir after the element ends. So, you can for example add this style to a table and the table will start in a new page when the page is printed: [sourcecode language="css" wraplines="false"] table.details {page-break-before: always;} [/sourcecode] Or you can have an style like this and use it as a page-breaker. [sourcecode language="css" wraplines="false"] .page-break {page-break-before: always;} [/sourcecode] [sourcecode language="html" wraplines="false"] <div class="page-break"></div>…
Read More

Adding an HTTP Handler to manage Images requests in .Net

Web programming
Building the Handler First, make the handler just creating a new class, make it use the IHttpHandler interface to make it "interfaceable". To make it part of the HttpHandler interface you need 2 methods: IsReusable and ProcessRequest. The method IsReusable is used to determine if the handler should be kept in memory and be reused by any request or should make a new instance for every request. In our case our handler should be reusable so it handles every request saving proc time and memory. The method ProcessRequest will get the request and send a response back, obviously. [sourcecode language="csharp" wraplines="false"] public class UserImagesHandler : IHttpHandler { public UserImagesHandler() { } public bool IsReusable { get { return true; } } public void ProcessRequest(HttpContext context) { HttpRequest request = context.Request;…
Read More

Using global objects in your page with a Master Page

Web programming
MasterPages are very useful to set the site structure like a header and footer, but, they can also help managing authorization or global issues of the site just declaring the needed variables on it and using them, if necessary, from the content pages or user controls. Let's see this with an example, imagine we need to add a site navigator object for showing dynamic menus, a navigator and other issues. First of all, we need to declare that variable as a public property: [sourcecode language="csharp" wraplines="false"] public MyLibrary.Navigator Navi {get; set;} [/sourcecode] We need to initialize the object (because we are using an object in this example) before accesing it or we'll find a null reference. If we do that in the Page_Load, we will find that the Page.Page_Load loads…
Read More

HTTP Server Status

Web standards
When a server answers a client request it gives an status code in the answer header that informs you if everything has gone ok or there has been any issue. Those statuses are divided in 5 groups: 1xx: Informational. 2xx: Success. 3xx: Redirect commands. Very important in SEO. 4xx: Client error. 5xx: Server error. Between them, the most common and the ones you may find while developing websites are these: 100: Continue. The first part of the request is accepted and you should continue sending the rest if there was anything else to send. You may find it if working with AJAX or webservices. 200: OK. The request has been answered without any problem. 201: Created. When a new resource has succesfully been created due to the request. 301: Moved…
Read More

Linking a .Net Label Control with an input

Web programming
In standard HTML label tags are used to assign some text to an input inside a form, giving the user the option to click the text in the label and causing the assigned input to be clicked too. This is very useful for CheckBoxes and Radio Buttons. [sourcecode language="html" wraplines="false"] <!-- Standard HTML4.1 --> <input type="checkbox" id="CHKCandies" value="1" /> <label for="CHKCandies">I want some candies</label> [/sourcecode] In .Net you can always assign some text to a CheckBox or Radio Button using its Text property, but, in case you want to add some functionality to that text like a link in the typical "[ ] I'm agree with the <a>Terms of use</a>" or similar you may find that the Text property in a Radio Button isn't enough. Fortunately the Label control not…
Read More

Paginate Grid Views in C#.Net

Web programming
Standard pagination To paginate a Grid view you only need to set the property "AllowPaging" to True and set an event for "PageIndexChanging". You can do all this just using the properties panel. Once you have it done you need to set the gridview actual IndexPage and DataBind() it again, something like this: [sourcecode language="csharp" wraplines="false"] protected void ResultsGrid_PageIndexChanging(object sender, GridViewPageEventArgs e) { ResultsGrid.PageIndex = e.NewPageIndex; LoadResults(); //This will redatabind the GV } [/sourcecode] Those easy steps will give you a Grid View with standard pagination, you can modify some of its properties like: AllowPaging: Remember this property has to be set to True or pagination will not be enabled. PageSize: Lets you decide how many rows will be shown per page. Position: Where to show the page navigator: (top,…
Read More

Load dynamic Web User Control in .Net

Web programming
One of the most common controls used in .Net is the Web User Control, which is in fact a website piece to be reused in different pages. You normally place them in the page while developing it just dropping it into the page and then using them as part of it, but, what if you want more than one of them in the same page and you don't know how many of them you are going to use? For doing that you can always set 10 or more of them in the page and then show as many as you need or, you can dynamically load as many of them as you need this way: First, I'm going to place the control in a namespace, this is not necessary, but…
Read More

Youtube doesn’t count views as complete visualizations

Web statistics
Uh oh! It seems the views counter on Youtube isn't as real as we could think it was! (well ok we didn't). With the new 10 hours limit for videos that Youtube has set we can now enjoy the 10 hours Nyan Cat. Yes, wonderful, I know. But if you have a look at the views counter you'll see more than 875.000 views (at the moment I'm writing this entry). So the question is... have 876.000 people really spent 10 hours viewing that video? So it looks like a Youtube visualization is not a visualization of the full video, neither half or a quarter or only its 10%... as it's hard to believe that nearly 900.000 people have watched even a 10% (1 hour) of that video. So it seems…
Read More

Web color schemes

Web design
When designing a website profesionally colors cannot be left to an approximate decision. As said in my post about design consistency, colors have to remain the same through all the page to give the user some info. So, if you choose red as the brand color it will not be a great idea to have 7 different reds around the page giving confusion to the user and showing the non good idea that your company departments do not coordinate properly or maybe your designer doesn't take his/her job seriously. Schemes are designed just for that purpose, there should be only a few colors and you should be able to play with them so that the website looks good and the usability is improved using them. As I read once, a…
Read More

Resizing image to some disk space in C#.Net

Web programming
Ive seen lots of tutorials of how to resize an image to some height or width, but none of them explain what to do in case you need to reduce its disk space to a limit of, say, 200Kb. This may not be the best way of dealing with this but it works: Getting and checking the image [sourcecode language="csharp" wraplines="false"] //Lets imagine im uploading an image from a .Net FileUpload object: System.Drawing.Image img = System.Drawing.Image.FromStream(Uploader.PostedFile.InputStream); //Now, I check the size limit: if (ImageSize(img) > 200){ img = ResizeImageTo200K(img); } [/sourcecode] Resizing it I just make a bucle to resize the image until its less than 200k or I may have get into an infinite loop: [sourcecode language="csharp" wraplines="false"] private System.Drawing.Image ResizeImageTo200K(System.Drawing.Image img) { int control = 0; while ((ImageSize(img)…
Read More

How to add the AJAX Control Toolkit to your project

Web programming
AJAX Control Toolkit is an extension made for ASP.Net that you can install for using many different AJAX controls in your website. They don't come with the basic Visual Studio installation so you have to install them if you want to use them (the AJAX core with update panels and timers comes with Visual Studio). Copied from ajax.net, just to save a copy! Download AJAX Control Toolkit from here. Extract the files and place the folder with them in a safe place. Launch Visual Studio and create a new ASP.NET Web Forms project or website. Open Default.aspx in the Visual Studio editor. Create a new Toolbox tab by right-clicking the Toolbox and selecting Add Tab. Name the new tab Ajax Control Toolkit. Right-click beneath the new tab and select the…
Read More
Close Bitnami banner
Bitnami