Friday, June 8, 2012

MVC on Windows 2008 R2

I had a I guess quite common situation:

I was assigned to deploy one of our MVC application on the Windows 2008 R2 server which has tightly locked down by the administrators - so no downloads from Internet.

Initial attempts to deploy using Web platform installer did not work. So thinking this is Web Platform Issue tried downloading 64 bit version and then installing that to find out that web platform was already installed. Seems like IIS on 2008 comes with installer? Don't know. So moved on to get 64 bit version of the MVC installer and landed to:

http://www.microsoft.com/en-us/download/details.aspx?id=4211

Just downloaded it-copied it to the server and BOOM!  I was able to compile and deploy my application.

Not quite complex but just lost some time there. May be you can use this information.  Good luck.

Wednesday, March 7, 2012

side by side configuration incorrect


Re: Side-By-Side Configuration is Incorrect

I found this link on the Office 2010 support website. It fixed the error. I had tried the sxstrace.exe route only to get frustrated.

Anyway here is the link: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=a5c84275-3b97-4ab7-a40d-3802b2af5fc2&displayLang=en
It will lead you to download the MS Visual C+++2008 SP1 pack. I just ran it and my Office stuff works fine now.

CTKevin

http://www.vistax64.com/software/245768-side-side-configuration-incorrect-2.html

GUYS Above post worked for me 5 stars....

Sunday, January 22, 2012

Embed html in label - devexpress





Many times I came across scenario in which I need to add HTML tag into the text of the ASPxLabel or TextBox etc.


Easiest way to accomplish this is setting EncodeHTML to false - which do not allow editor to keep any of its values that are HTML as HTML and RENDERED as PURE HTML.


e.g. through server side...


aspxlabel.text = "111<br>2222";
aspxlabel.encodehtml = false;




<dxe:ASPxLabel runat="server" ID="ASPxLabel1" ClientInstanceName="lblShortFont" class="largeDonationsStyle"  EncodeHtml ="false" Text="bkasd asd <a href='mailto:info@kaliya.com'> info@kaliya.com</a> or call (800) 400-2000" Font-Size="X-Small">
</dxe:ASPxLabel>

Monday, January 16, 2012

CallBack and Postback differences

Awesome explanation about Callback and postback

http://stackoverflow.com/questions/365100/difference-between-a-postback-and-a-callback

BELOW CONTENT IS COPIED FROM STACKOVERFLOW:


A Postback occurs when the data (the whole page) on the page is posted from the client to the server..ie the data is posted-back to the server, and thus the page is refreshed (redrawn)...think of it as 'sending the server the whole page (asp.net) full of data'.
On the other hand, a callback is also a special kind of postback, but it is just a quick round-trip to the server to get a small set of data (normally), and thus the page is not refreshed, unlike with the postback...think of it as 'calling the server, and receiving some data back'
With Asp.Net, the ViewState is not refreshed when a callback is invoked, unlike with a postback.
The reason that the whole page is posted with ASP.Net is because ASP.Net encloses the whole page in a <form> with a post method, and so when a submit button is clicked in the page, the form is sent ot the server with all of the fields that are in the form...basically the whole page itself
If you are using FireBug (for Firefox), you can actually see callbacks being invoked to the server in theConsole. That way, you will see what specific data is being sent to the server (Request) and also the data the server sent you back (Response)

The below image illustrates the Page Life Cycles of both a postback and a callback in a ASP.NET based Website:
ASP.NET Page Life Cycles

Saturday, October 22, 2011

ViewState HttpPostedFile

When I was trying to implement the functionality of uploading file I looked into putting HttpPostedFile into ViewState -

FileUpload.PostedAs is a HttpPostedFile

BAD idea. - There is no constructor for HttpPostedFile.


SO DO NOT GO THAT PATH!! You can cache the file content. Check the blog


Friday, October 21, 2011

File upload with two different ways!!!

In recent project I had to make two different types of FileUploads work -
1. Asp.net fileupload a
2. Ajax - AsyncFileupload

Both implementations were not that hard. Complete description is as follows:

Asp.net FileUpload

Visible="false" />
ValidationExpression="^(([a-zA-Z]:)|(\\{1}\w+)\$?)(\\(\w.*))+(.xls|.xlsx)$" ControlToValidate="fuPricingAttachment">


In above example - is the control used and the regex is for informing that only .xls and .xlsx types of files can be uploaded. ValidationGroup allows to validate the content when 'submit' button is clicked.

I did create -

public string pricingFileGuid
{
get
{
if (ViewState["strPricingFileGuid"] != null)
return ViewState["strPricingFileGuid"].ToString();
else
return string.Empty;
}
set { ViewState["strPricingFileGuid"] = value; }
}

so that I can cache the file content with key of GUID.

Core piece of storing file content is - this way content does not get stored until user decides to save the file content in the database by hitting 'Save' or 'Submit'

var fileKey = Guid.NewGuid();
if (!string.IsNullOrEmpty(fileName))
{
var fileStream = new Byte[fuPricingAttachment.PostedFile.ContentLength];
fuPricingAttachment.PostedFile.InputStream.Read(fileStream, 0, fuPricingAttachment.PostedFile.ContentLength);
Cache[fileKey.ToString()] = fileStream;
this.pricingFileGuid = fileKey.ToString();
}

The code which Saves file to file share and to database :

if (!string.IsNullOrEmpty(this.generalFileGuid))
{
var fileStream = new Byte[((Byte[])Cache[this.generalFileGuid]).Length];

try
{
// Open file for reading
System.IO.FileStream _FileStream = new System.IO.FileStream(lnkGeneralAttachment.Text, System.IO.FileMode.Create, System.IO.FileAccess.Write);
// Writes a block of bytes to this stream using data from a byte array.
_FileStream.Write(fileStream, 0, fileStream.Length);
// close file stream
_FileStream.Close();

}
catch (Exception _Exception)
{
throw new Exception("Error while uploading file.");
}
}

At any point if you have any questions/comments or you want full code of pages let me know and I might be able to provide it to you within no time.

I will upload AsyncFileUpload code tomorrow :) happy coding!



Wednesday, September 21, 2011

Custom project templates

Easy pizy creation of project template
http://saraford.net/2008/10/16/did-you-know-you-can-create-project-templates-336/

Custom project templates for C# can be compiled into a zip file and you just need to copy to the and visual studio should pick up the project templates.

C:\Users\[your name]\Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual C#

Looks like there are several ways to create project templates - zip file creation seems easiest.