tag:blogger.com,1999:blog-63072968507398350652024-02-20T19:20:29.026+01:00.NET Framework developer's tipsThis blog dedicated to developing of windows applications, web applications, web services on Microsoft .NET Framework platform. Here are discussed
questions about ASP.NET, AJAX, Silverlight, DotNetNuke, LINQ, JavaScript, ADO.NET ets.AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.comBlogger24125tag:blogger.com,1999:blog-6307296850739835065.post-20975520626837127232010-11-26T14:44:00.005+01:002010-11-26T15:06:59.907+01:00ASP.NET MVC 2 Error rised using RenderAction : The controller for path '/' was not found or does not implement IController.When I try to use RenderAction in ASP.NET MVC2 view:<br /><br /><pre class="csharpcode"><br /><span class="asp"><%</span>Html.RenderAction(<span class="str">"BrowserVersion"</span>, <span class="str">"HomeController"</span>); <span class="asp">%></span></pre><br /><br />I got the error below:<br /><br /><p class="rederror">The controller for path '/' was not found or does not implement IController.</p><br /><br />Code for HomeController:<br /><br /><pre class="csharpcode"><br /><span class="kwrd">public</span> <span class="kwrd">class</span> HomeController : Controller<br />{<br /><br /> [ChildActionOnly]<br /> <span class="kwrd">public</span> ActionResult BrowserName()<br /> {<br /> ViewData[<span class="str">"BrowserName"</span>] = Request.Browser.Browser;<br /> <span class="kwrd">return</span> View();<br /> }<br /><br />}</pre><br /><a name='more'></a><br />To get rid of the error the call to RenderAction should be RenderAction("BrowserName", "Home") without the Controller suffix.AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com1tag:blogger.com,1999:blog-6307296850739835065.post-90256330496385587232010-02-23T14:35:00.005+01:002010-03-10T16:29:22.127+01:00MS SQL Server Reporting Services error: The report server has encountered a configuration errorAfter install of the Sql Server 2005 I got the error:<br /><br /><span style="font-weight: bold;">The report server has encountered a configuration error. See the report server log files for more information. (rsServerConfigurationError) </span><br /><span style="font-weight: bold;">Access to the path 'C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\RSReportServer.config' is denied.</span><br /><br /><a name='more'></a><br /><br />To resolve this error you should to give the right to read the file RSReportServer.config for ASPNET account.AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-74486393452228974872010-01-21T14:42:00.004+01:002010-03-10T16:30:18.825+01:00How to restore missing controls in Visual Studio 2008 ToolboxI encountered a problem today when I tried to use Visual Studio 2008.<br /><br />When I created a Windows forms project, the controls in Toolbox were missing. The usual remedy of right-clicking the Toolbox and then selecting Reset Toolbox did not help.<br /><br />C:\Documents and Settings\[User Name]\Local Settings\Application Data\Microsoft\VisualStudio\9.0<br /><br /><a name='more'></a><br /><br />And within this folder are some hidden files. Simply remove the following files:<br /><br />"toolbox.tbd", "toolboxIndex.tbd", "toolbox_reset.tbd", "toolboxIndex_reset.tbd"<br /><br />Then restart Visual Studio 2008. Your controls should now come back up!AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-37350540656781573832009-12-07T15:30:00.004+01:002010-03-10T16:30:51.334+01:00How to generate a transparent GIF image using C#<span style="font-weight:bold;">There is apparently no easy way to generate a transparent GIF image using the .NET framework. Microsoft provided a method in the Bitmap class called MakeTransparent() but it doesn’t work for GIFs, it only seems to work for PNGs.</span><br /><br />To create a transparent GIF you need to recreate the color table of the image using Imaging APIs. Unfortunately, this can be pretty slow for an ASP.NET Web application, and it has a lot of overhead, so I needed an alternative.<br /><br />Solution:<br /><br />The alternative is to alter the color table directly using the GIF specification. To implement this, I needed to save the non-transparent GIF to a MemoryStream, and then go through the binary data, updating the color table with the new transparency bits.<br /><br /><a name='more'></a><br /><br /><!-- code formatted by http://manoli.net/csharpformat/ --><br /><pre class="csharpcode"><br /> <span class="rem">/// <summary></span><br /> <span class="rem">/// Returns a transparent background GIF image from the specified Bitmap.</span><br /> <span class="rem">/// </summary></span><br /> <span class="rem">/// <param name="bitmap">The Bitmap to make transparent.</param></span><br /> <span class="rem">/// <param name="color">The Color to make transparent.</param></span><br /> <span class="rem">/// <returns>New Bitmap containing a transparent background gif.</returns></span><br /> <span class="kwrd">public</span> Bitmap MakeTransparentGif(Bitmap bitmap, Color color)<br /> {<br /> <span class="kwrd">byte</span> R = color.R;<br /> <span class="kwrd">byte</span> G = color.G;<br /> <span class="kwrd">byte</span> B = color.B;</p><br /> MemoryStream fin = <span class="kwrd">new</span> MemoryStream();<br /> bitmap.Save(fin, System.Drawing.Imaging.ImageFormat.Gif);<br /> MemoryStream fout = <span class="kwrd">new</span> MemoryStream((<span class="kwrd">int</span>)fin.Length);<br /> <span class="kwrd">int</span> count = 0;<br /> <span class="kwrd">byte</span>[] buf = <span class="kwrd">new</span> <span class="kwrd">byte</span>[256];<br /> <span class="kwrd">byte</span> transparentIdx = 0;<br /> fin.Seek(0, SeekOrigin.Begin);<br /> <span class="rem">//header</span><br /> count = fin.Read(buf, 0, 13);<br /> <span class="kwrd">if</span> ((buf[0] != 71) || (buf[1] != 73) || (buf[2] != 70)) <span class="kwrd">return</span> <span class="kwrd">null</span>; <span class="rem">//GIF</span><br /> fout.Write(buf, 0, 13);<br /> <span class="kwrd">int</span> i = 0;<br /> <span class="kwrd">if</span> ((buf[10] & 0×80) > 0)<br /> {<br /> i = 1 << ((buf[10] & 7) + 1) == 256 ? 256 : 0;<br /> }<br /> <span class="kwrd">for</span> (; i != 0; i—)<br /> {<br /> fin.Read(buf, 0, 3);<br /> <span class="kwrd">if</span> ((buf[0] == R) && (buf[1] == G) && (buf[2] == B))<br /> {<br /> transparentIdx = (<span class="kwrd">byte</span>)(256 – i);<br /> }<br /> fout.Write(buf, 0, 3);<br /> }<br /> <span class="kwrd">bool</span> gcePresent = <span class="kwrd">false</span>;<br /> <span class="kwrd">while</span> (<span class="kwrd">true</span>)<br /> {<br /> fin.Read(buf, 0, 1);<br /> fout.Write(buf, 0, 1);<br /> <span class="kwrd">if</span> (buf[0] != 0×21) <span class="kwrd">break</span>;<br /> fin.Read(buf, 0, 1);<br /> fout.Write(buf, 0, 1);<br /> gcePresent = (buf[0] == 0xf9);<br /> <span class="kwrd">while</span> (<span class="kwrd">true</span>)<br /> {<br /> fin.Read(buf, 0, 1);<br /> fout.Write(buf, 0, 1);<br /> <span class="kwrd">if</span> (buf[0] == 0) <span class="kwrd">break</span>;<br /> count = buf[0];<br /> <span class="kwrd">if</span> (fin.Read(buf, 0, count) != count) <span class="kwrd">return</span> <span class="kwrd">null</span>;<br /> <span class="kwrd">if</span> (gcePresent)<br /> {<br /> <span class="kwrd">if</span> (count == 4)<br /> {<br /> buf[0] |= 0×01;<br /> buf[3] = transparentIdx;<br /> }<br /> }<br /> fout.Write(buf, 0, count);<br /> }<br /> }<br /> <span class="kwrd">while</span> (count > 0)<br /> {<br /> count = fin.Read(buf, 0, 1);<br /> fout.Write(buf, 0, 1);<br /> }<br /> fin.Close();<br /> fout.Flush();<br /> <span class="kwrd">return</span> <span class="kwrd">new</span> Bitmap(fout);<br /> }</pre><br /><br />I've used this code for creating images for <a href="http://avto-credit.com">калькулятор на автокредит</a>AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-27735182469572414462009-10-28T13:35:00.007+01:002010-03-10T16:31:11.112+01:00How to increase sound level using C#To increase sound level using C# first of all you should add line:<br /><pre class="csharpcode"><br /><span class="kwrd">using</span> System.Runtime.InteropServices;</pre><br />to allow using COM Interop in your class.<br /><br />Next we derlare two functions from an unmanaged DLL:<br /><br /><a name='more'></a><br /><br /><pre class="csharpcode"><br /> [DllImport(<span class="str">"winmm.dll"</span>)]<br /> <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">int</span> waveOutGetVolume(IntPtr hwo, <span class="kwrd">out</span> <span class="kwrd">uint</span> dwVolume);<br /><br /> [DllImport(<span class="str">"winmm.dll"</span>)]<br /> <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">int</span> waveOutSetVolume(IntPtr hwo, <span class="kwrd">uint</span> dwVolume);</pre><br /><br /><br />Using these functions, we can increase or decrease the sound level of the sound card.<br />The following example shows how to mute the sound.<br /><br /><pre class="csharpcode"><br />waveOutSetVolume(IntPtr.Zero, 0);</pre><br /><br />Check out <a href="http://avto-credit.com/Calculator.aspx">калькулятор автокредита</a>AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-1203008234001098042009-10-23T14:01:00.004+02:002010-03-10T16:31:39.872+01:00Capture Sound and save into wav or mp3 file .NET C# exampleIt's surprising that there are no components for sound capturing in .NET Framework 3.5. Even designers of WPF and Silverlight 2.0 were focused on graphics so deeply, that they forgot about applications recording sound from user's microphone. It is said that the next version of Silverlight will provide such functionality.<br /><br />However, what you often want to achieve is to store the recorded sound in MP3 file (or send it as MP3 stream). That's legally complicated due to MP3 patent constraints. And for the same legal reason, we can assume that we will not see MP3 functionality in Microsoft technologies soon (there is WMA instead).<br /><br /><a name='more'></a><br />This article uses a subset of C# MP3 Compressor libraries written by Idael Cardoso which in turn are partially based on A low level audio player in C# by Ianier Munoz. See this website for technical and copyright information regarding the LAME project.<br /><br />In codeproject.com/KB/audio-video/Mp3SoundCapture.aspx you find an easy to use .NET 3.5 component, providing Sound Capturing functionality for a Windows application. It outputs data as raw PCM samples or a regular WAV file. Or you can just set one boolean property to use LAME DLL and perform MP3 compression on the fly.AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-22980680547018179692009-07-29T09:31:00.003+02:002010-03-10T16:32:03.770+01:00How to get data from Firebird database using MS SQL Server stored procedureIn solving one of the tasks (<a href="http://avto-credit.com">рассчет автокредита</a>) I needed an opportunity to perform stored procedure of SQL Server 2005, to receive data from the FireBird database.<br /> <br />Typically stored procedure in T-SQL can not do this, so I wrote a stored procedure in C#, which receives the necessary data to the DataTable(s), from where then method SqlContext.Pipe.SendResultsRow, passing a string SQL Server.<br />Here is the example:<br /><br /><a name='more'></a><br /><br /><pre class="csharpcode"><br /><span class="kwrd">public</span> <span class="kwrd">class</span> SQLFIREBIRDCLR<br />{<br /><br /> [SqlProcedure()]<br /> <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> ProcedureToFirebird(SqlString sServerName, SqlString sDatabaseName)<br /> {<br /><br /> FbConnectionStringBuilder cs = <span class="kwrd">new</span> FbConnectionStringBuilder();<br /> cs.DataSource = sServerName.ToString();<br /> cs.Database = sDatabaseName.ToString();<br /> cs.UserID = <span class="str">"SYSDBA"</span>;<br /> cs.Password = <span class="str">"masterkey"</span>;<br /> cs.Dialect = 3;<br /> <span class="kwrd">string</span> ConnectionString = cs.ToString();<br /><br /> SqlDataRecord record = <span class="kwrd">new</span> SqlDataRecord(<br /> <span class="kwrd">new</span> SqlMetaData(<span class="str">"field1"</span>, SqlDbType.SmallInt),<br /> <span class="kwrd">new</span> SqlMetaData(<span class="str">"field2"</span>, SqlDbType.NVarChar, 30));<br /><br /><br /> SqlContext.Pipe.SendResultsStart(record);<br /> DataTable dt = <span class="kwrd">new</span> DataTable();<br /> FbConnection conn = <span class="kwrd">new</span> FbConnection(ConnectionString);<br /> <span class="kwrd">using</span> (conn)<br /> {<br /> <span class="kwrd">string</span> ssql = <span class="str">"select field1, field2 from table1"</span>;<br /> FbCommand command = <span class="kwrd">new</span> FbCommand(ssql, conn);<br /> FbDataAdapter adapt = <span class="kwrd">new</span> FbDataAdapter(command);<br /> conn.Open();<br /> adapt.Fill(dt);<br /><br /> }<br /><br /> <span class="kwrd">foreach</span> (DataRow dr <span class="kwrd">in</span> dt.Rows)<br /> {<br /> record.SetValue(0, dr[<span class="str">"field1"</span>]);<br /> record.SetValue(1, dr[<span class="str">"field2"</span>]);<br /> SqlContext.Pipe.SendResultsRow(record);<br /> }<br /> SqlContext.Pipe.SendResultsEnd();<br /> }<br /><br />}</pre>AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-27274084163251086472009-05-06T14:49:00.003+02:002009-05-06T15:04:31.032+02:00How to connect to SQL Server 2008 using 2005While supporting the website <a href="http://avto-credit.com/">калькулятор на автокредит</a> I encountered a problem when I use SQL Server Management Studio in SQL Server 2005 to connect to an instance of SQL Server 2008. <br /> To solve this problem, I installed Microsoft SQL Server 2005 Service Pack 2. After that I also installed "Cumulative update package 12 for SQL Server 2005 Service Pack 2 (server and client)".<br />And, voila, it works!AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-27911592967704054342009-04-28T14:59:00.006+02:002010-03-10T16:32:37.921+01:00How to sort the hierarchical recursive query in SQL Server 2005In SQL Server 2005 was an innovation in the form of CTE (common table expressions), which enables the hierarchical recursive queries to the database. While designing the web site <a href="http://avto-credit.com/">автокредит на автомобиль</a> I have a challenge: to display the hierarchical structure of pages of the site. The query also have to sort sort the data on a field "pageorder" from the pages with the same level of hierarchy.<br /><br />The structure of the table looks like this:<br /><br /><pre class="csharpcode"><br /><span class="kwrd">CREATE</span> <span class="kwrd">TABLE</span> [dbo].[pages](<br /> [id] [<span class="kwrd">int</span>] <span class="kwrd">NULL</span>,<br /> [pid] [<span class="kwrd">int</span>] <span class="kwrd">NULL</span>,<br /> [title] [nvarchar](<span class="kwrd">max</span>) <span class="kwrd">NULL</span>,<br /> [pageorder] [<span class="kwrd">int</span>] <span class="kwrd">NULL</span><br />) <span class="kwrd">ON</span> [<span class="kwrd">PRIMARY</span>]</pre><br /><br />The field "pid" points to id of the parent record. In addition, there have to exist a root(entry) record, whose pid = NULL.<br /><br />Below is a sample request that selects and sorts the hierarchical data:<br /><br /><a name='more'></a><br /><pre class="csharpcode"><br /><span class="kwrd">WITH</span> CTE(pid, id, title, <span class="kwrd">level</span>, pageorder, pathstr) <span class="kwrd">AS</span><br />(<br /><span class="kwrd">SELECT</span> pid, id, title, 0, 0, <span class="kwrd">CAST</span> (<span class="str">'/'</span> <span class="kwrd">AS</span> <span class="kwrd">VARCHAR</span>(<span class="kwrd">MAX</span>))<br /><span class="kwrd">FROM</span> pages<br /><span class="kwrd">WHERE</span> pid <span class="kwrd">IS</span> <span class="kwrd">NULL</span><br /><span class="kwrd">UNION</span> <span class="kwrd">ALL</span><br /><span class="kwrd">SELECT</span> e.pid, e.id, e.title, <span class="kwrd">level</span> + 1, e.pageorder, d.pathstr + <span class="kwrd">CAST</span>(e.pageorder <span class="kwrd">as</span> <span class="kwrd">VARCHAR</span>) + <span class="str">'/'</span><br /><span class="kwrd">FROM</span> pages e<br /> <span class="kwrd">INNER</span> <span class="kwrd">JOIN</span> CTE d<br /> <span class="kwrd">ON</span> e.pid = d.id<br /><br />)<br /><span class="kwrd">SELECT</span> pid, id, replicate(<span class="str">'... '</span>, <span class="kwrd">level</span>) + title <span class="kwrd">as</span> title, <span class="kwrd">level</span>, pageorder, pathstr<br /><span class="kwrd">FROM</span> CTE<br /><span class="kwrd">ORDER</span> <span class="kwrd">BY</span> pathstr</pre><br /><br />Here's what we get after execution the query:<br /><br /><pre class="csharpcode"><br />pid id level pageorder pathstr title<br />----------- ----------- ----------- ----------- ----------- ---------------------------------<br />NULL 1 0 0 / Main<br />1 4 1 3 /3/ ... Products<br />4 5 2 3 /3/3/ ... ... cars<br />4 8 2 6 /3/6/ ... ... motorcycles<br />1 2 1 6 /6/ ... Services<br />2 6 2 3 /6/3/ ... ... Lease<br />2 3 2 6 /6/6/ ... ... Loans<br />1 7 1 9 /9/ ... about website<br /><br />(8 row(s) affected)</pre>AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-15380907838695436242009-03-25T13:08:00.004+01:002010-03-10T16:33:36.391+01:00How to disable passing of HTTP header "Expect: 100-continue" using HttpWebRequest in .NET Framework in C#?How to disable passing of HTTP header "Expect: 100-continue" using HttpWebRequest in .NET Framework in C#?<br />По умолчанию, при выполнении веб-запроса, используя класс HttpWebRequest, .NET Framework добавляет HTTP заголовок (HTTP header) "Expect: 100-continue". Для того, чтобы запретить формирование этого заголовка нужно сделать следующее:<br /><br />As default when You use HttpWebRequest class to execute web-requests it appends HTTP header "Expect: 100-continue" to it's headers collection. To disable passing of HTTP header "Expect: 100-continue" using HttpWebRequest You can do following:<br /><br /><a name='more'></a><br />HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://a-kicker.blogspot.com");<br />myHttpWebRequest.ServicePoint.Expect100Continue = false;AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-7019320106771095282009-03-25T12:48:00.001+01:002009-03-25T12:50:57.945+01:00How to place DateTimePicker onto ToolStrip control in Windows Forms .NET application?To place DateTimePicker onto ToolStrip control in Windows Forms .NET application you had to do following:<br /><br />DateTimePicker dateTimePcr = new DateTimePicker();<br />toolStrip1.Items.Add(new ToolStripControlHost(dateTimePcr));AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-47647631791043116032009-03-03T08:58:00.003+01:002010-03-10T16:33:06.340+01:00How to enabling Gzip and Deflate HTTP Compression in ASP.NET pagesIf your ASP.NET web application doesn't already contain a Global.asax file, create a new one using notepad. Then insert following code in it:<br /><br /><pre class="csharpcode"><br /><%@ Application Language=<span class="str">"C#"</span> %><br /><%@ Import Namespace=<span class="str">"System.IO"</span> %><br /><%@ Import Namespace=<span class="str">"System.IO.Compression"</span> %><br /><br /><a name='more'></a><br /><script runat=<span class="str">"server"</span>><br /><span class="kwrd">void</span> Application_PreRequestHandlerExecute(<span class="kwrd">object</span> sender, EventArgs e)<br />{<br /> HttpApplication app = sender <span class="kwrd">as</span> HttpApplication;<br /> <span class="kwrd">string</span> acceptEncoding = app.Request.Headers[<span class="str">"Accept-Encoding"</span>];<br /> Stream prevUncompressedStream = app.Response.Filter;<br /><br /> <span class="kwrd">if</span> (!(app.Context.CurrentHandler <span class="kwrd">is</span> Page) ||<br /> app.Request[<span class="str">"HTTP_X_MICROSOFTAJAX"</span>] != <span class="kwrd">null</span>)<br /> <span class="kwrd">return</span>;<br /><br /> <span class="kwrd">if</span> (acceptEncoding == <span class="kwrd">null</span> || acceptEncoding.Length == 0)<br /> <span class="kwrd">return</span>;<br /><br /> acceptEncoding = acceptEncoding.ToLower();<br /><br /> <span class="kwrd">if</span> (acceptEncoding.Contains(<span class="str">"deflate"</span>) || acceptEncoding == <span class="str">"*"</span>)<br /> {<br /> <span class="rem">// defalte</span><br /> app.Response.Filter = <span class="kwrd">new</span> DeflateStream(prevUncompressedStream,<br /> CompressionMode.Compress);<br /> app.Response.AppendHeader(<span class="str">"Content-Encoding"</span>, <span class="str">"deflate"</span>);<br /> } <span class="kwrd">else</span> <span class="kwrd">if</span> (acceptEncoding.Contains(<span class="str">"gzip"</span>))<br /> {<br /> <span class="rem">// gzip</span><br /> app.Response.Filter = <span class="kwrd">new</span> GZipStream(prevUncompressedStream,<br /> CompressionMode.Compress);<br /> app.Response.AppendHeader(<span class="str">"Content-Encoding"</span>, <span class="str">"gzip"</span>);<br /> }<br />}<br /></script></pre>AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-56545315980315292022009-02-19T09:46:00.003+01:002009-02-19T09:59:53.469+01:00Dotnetnuke: how to force dotnetnuke to send welcome e-mail as HTML not plain textTo force dotnetnuke to send welcome e-mail as HTML, you just have to modify MAIL_USER_REGISTRATION_PUBLIC_BODY.Text or EMAIL_USER_REGISTRATION_PRIVATE_BODY.Text strings in language editor. DNN Framework check if the mailbody contains html code and send e-mail in corresponding mode.AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-36824958088613485932009-02-18T15:09:00.004+01:002009-02-18T15:22:10.509+01:00How to show name of sender before the e-mail address using ASP.Net MailMessage objectHow to show name of sender before the e-mail address using ASP.Net MailMessage object? It's very simple. Just look at following example:<br /><br /><pre class="csharpcode"><br />System.Net.Mail.MailMessage message = <span class="kwrd">new</span> System.Net.Mail.MailMessage();<br />message.From = <span class="kwrd">new</span> System.Net.Mail.MailAddress(<span class="str">"admin of TEST.COM <admin@test.com>"</span>);</pre><br /><br />That code was used in writing website <a href="http://crash-tests.net/" target="_blank">Краш-тесты автомобилей</a>AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-41329492314995470122009-02-05T12:49:00.005+01:002010-03-10T16:34:47.708+01:00How to change in code the title of web page in Dotnetnuke based website?In the ordinal web page to change programmatically the title of the .aspx page is simple:<br /><br /><pre class="csharpcode"><br /><span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)<br />{<br /> <span class="kwrd">this</span>.Title = <span class="str">"The ordinal web page"</span>;<br />}<br /></pre><br /><br />In dotnetnuke's module that code will not help. The title of the web page will be created by DNN's core.<br /><br />But we can solve this problem. The code below shows how to achieve this:<br /><a name='more'></a><br /><pre class="csharpcode"><br /><span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)<br />{<br /> DotNetNuke.Framework.CDefault page = (DotNetNuke.Framework.CDefault)<span class="kwrd">this</span>.Page;<br /> page.Title = <span class="str">"Веб-страница в Dotnetnuke"</span>;<br />}<br /><br /></pre><br /><br />You can see <a href="http://my11a.net" target="_balnk">here</a> how it works.AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-67862275302332481762009-02-03T12:11:00.005+01:002010-03-10T16:35:01.686+01:00LINQ to SQL: How to get a Random Record from a Table inside the SQL Server DatabaseI wanted to get a random record from a particular table on the SQL Server database. For my case, I had a table containing quotes, and I wanted to randomly pick on to show on one corner of my web site. I am also using LINQ to SQL for this web site, so the solution here will be using LINQ, although the approach is pretty simple and flexible.<br /><br />The idea centers on ordering the records by a random parameter an then getting the TOP n number of records. The NEWID() function from SQL Server makes a great candidate for getting a random parameter since this method generates a GUID.<br /><br />In SQL Server, try out this query.<br /><br /><pre class="csharpcode"><br /><span class="kwrd">SELECT</span> * <span class="kwrd">FROM</span> Quote <span class="kwrd">ORDER</span> <span class="kwrd">by</span> NEWID();</pre><br /><pre class="csharpcode"><br />SELECT TOP 1 * FROM Quote ORDER by NEWID();</pre><br /><a name='more'></a><br />Now for our code, we need to duplicate this behavior on .NET. I needed to get an equivalent of NEWID() on my LINQ to SQL DBML. Note that we cannot use NEWID() directly on a stored procedure or function since SQL Server will complain with an “Invalid use of side-effecting or time-dependent operator in 'newid' within a function” error. The workaround is to create a view that uses the NEWID() and then a function that selects from the view.<br /><br /><pre class="csharpcode"><br /><span class="kwrd">CREATE</span> <span class="kwrd">VIEW</span> [dbo].[RandomView]<br /><span class="kwrd">AS</span><br /><span class="kwrd">SELECT</span> NEWID() <span class="kwrd">As</span> ID<br /><span class="kwrd">GO</span><br /><span class="kwrd">CREATE</span> <span class="kwrd">FUNCTION</span> [dbo].[GetNewId]<br />(<br />)<br /><span class="kwrd">RETURNS</span> uniqueidentifier<br /><span class="kwrd">AS</span><br /><span class="kwrd">BEGIN</span><br /><span class="kwrd">RETURN</span> (<span class="kwrd">SELECT</span> ID <span class="kwrd">FROM</span> RandomView)<br /><span class="kwrd">END</span><br />GO</pre><br /><br />On our DBML, we simple drag and drop the Quote table and the GetNewID function to our designer. The code below takes a random record from the Quotes table.<br /><br /><pre class="csharpcode"><br />DataContext db = <span class="kwrd">new</span> QuoteDataContext();<br />var quote = db.Quote.OrderBy(q => db.GetNewId()).First();</pre><br /><br />Actually, once the objects are in place, we can use them to get x number of random records from any table.AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com2tag:blogger.com,1999:blog-6307296850739835065.post-91292113858900963302009-01-30T09:42:00.004+01:002010-03-10T16:35:03.152+01:00Remember Me not working for Login in DotNetNuke based websiteThe "Remember Me" feature of the DotNetNuke Login is implemented by placing an encrypted authentication cookie on the user's machine.<br /><br />The expiration of this cookie is controlled through the timeout value in the Forms Autentication node the web.config.<br /><br /> <span style="font-weight:bold;">< forms name=".DOTNETNUKE" protection="All" timeout="60" cookieless="UseCookies" /></span><br /><br />The default setting is 60 minutes, so it can't remember anyone for very long (I call it goldfish mode).<br /><br />To extend the time your users are remembered make the timeout value larger.<br /><a name='more'></a><br /> <span style="font-weight:bold;">< forms name=".DOTNETNUKE" protection="All" timeout="20160" cookieless="UseCookies" /></span><br /><br /><br />You can also make it a sliding expiration which means that every time someone visits with an auth cookie thier time will be reset to the value in the timeout. That way you can keep the timeout shorter, but still convienient for your visitors that make it back to your site before it expires.<br /><br /> <span style="font-weight:bold;">< forms name=".DOTNETNUKE" protection="All" timeout="10080" slidingExpiration="true"<br />cookieless="UseCookies" /></span><br /><br />You can see <a href="http://my11a.net">here</a> how it works.AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-31767576068854455412009-01-13T13:20:00.006+01:002009-01-13T13:37:11.396+01:00display:inline-block for Firefox, Internet Explorer and OperaFor correct displaying of the elements with display:inline-block property in Firefox Internet Explorer, Opera you have to write this in style sheet:<br /><br /><pre class="csharpcode"><br /> display:-moz-inline-stack;/*Firefox need this to simulate display:inline-block*/<br /><br /> display:inline-block; /*IE does not apply this to Block Element, and Firefox does not render this, too*/<br /> <br /> _overflow:hidden;/*fix IE6 to expanded content*/<br /> zoom:1;/*trigger hasLayout*/<br /> *display:inline;/*once hasLayout is true, set display:inline to block element will make display:inline behave like display:inline-block*</pre>AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com1tag:blogger.com,1999:blog-6307296850739835065.post-88111748762199249502009-01-06T10:03:00.005+01:002010-03-10T16:35:09.561+01:00How to reduce the size of the database in Microsoft SQL ServerOn hosting server often exists database quota for MS SQL Server. Even if your database contains small amount of data, but there is goes intensive adding/modifacation of the data, in some point the size of the data could exceed quota and your account may be suspended.<br /> This happens because of growth of the <span style="font-weight:bold;">transaction log</span>.<br />To clear transaction log you can execute the following command:<br /><a name='more'></a><br /><span style="font-weight:bold;">BACKUP LOG [databasename] WITH TRUNCATE_ONLY</span><br /><br />After this you will need to make Shrink Database<br /><br />For example. One of my databases decreased form 890MB to 12MB. <br /><br />It should be noted, before the next backup your database remains unprotected (failure of equipment, etc.) as well as transaction log, we cleaned.AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-86591547760830723332008-12-24T15:15:00.002+01:002008-12-24T15:20:27.595+01:00How to change string "You are here" in Dotnetnuke web site to other languageHow to change string "You are here" in Dotnetnuke's web site to other language?<br /><br />If you want to translate it, you need access to you DNN installation via file system. Look for the Skin folder (/Portals/_defauls/Skins/MinimalExtrophy) and inside there is a folder /App_localResources with a single file "index.ascx.resx" you need to copy to index.ascx.sv-SV.resx and edit using a text editor. you will find "you are here" near the end of the file and may overwrite it with your localization.<br /><br />This works to DNN version 4.9 and above. How it works you may see <a href="http://my11a.net">here</a>AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-14539446304803226922008-10-29T12:21:00.003+01:002008-10-29T12:32:12.834+01:00Нow to dynamically change query for ListView linked to LinqDataSource?In order to dynamically change query for ListView linked to LinqDataSource you have to handle <strong>OnSelecting</strong> event for <strong> LinqDataSource. </strong>.<br /><br />For example:<br /><br /><pre class="csharpcode"><br /> <span class="kwrd">protected</span> <span class="kwrd">void</span> dsMates_Selecting(<span class="kwrd">object</span> sender, LinqDataSourceSelectEventArgs e)<br /> {<br /> <span class="kwrd">if</span> (Request.Params[<span class="str">"classMateId"</span>] != <span class="kwrd">null</span>)<br /> {<br /> <span class="kwrd">int</span> mateId;<br /> <span class="kwrd">if</span> (<span class="kwrd">int</span>.TryParse(Request.Params[<span class="str">"classMateId"</span>], <span class="kwrd">out</span> mateId))<br /> {<br /> <span class="kwrd">using</span> (DataClassesPrivateMsgDataContext db = <span class="kwrd">new</span> DataClassesPrivateMsgDataContext())<br /> {<br /> e.Result = db.Classmates.Where(mate => mate.Id == mateId).FirstOrDefault();<br /> }<br /> }<br /> }<br /> }</pre><br />How does it works you can see here: <a href="http://my11a.net/нашкласс/tabid/59/Default.aspx">11-A</a>AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-24765613274697940712008-10-22T12:03:00.002+02:002008-10-22T12:16:47.866+02:00Code formatter for C#, JavaScript, HTML, ASP.NET for your blogWhen posting posts to my blog often need to insert some code saples into the text. It's good to show well formatted code for readers.<br /><br />If found good free online tool for my purposes: <br /><br /><span style="font-weight:bold;">www.manoli.net/csharpformat/format.aspx</span><br /><br />This tool allows you to format your C#, VB, HTML, XML, T-SQL or MSH (code name Monad) code for publishing on a web site or in a blog.<br /><br />All welcome!AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-84873603594032589812008-10-17T21:13:00.003+02:002008-10-17T21:39:09.526+02:00Animated gif files for AJAX loaderWhen you develop AJAX-based website you probably want beautiful animated gif image(s) to show to the user an AJAX activity (when user have to wait while AJAX is getting some data from server). So I found very useful website "ajaxload.info" where you can generate different "AJAX-loading" animated gif images. There is many templates. You can change colors, size, opacity for gif's.<br /><br />If you using "Opera" than you can install wiget named "Animated loading image generator!" and generate gif's not quit your favourite website "<a href="http://avto-credit.com">калькулятор автокредита</a>"AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com0tag:blogger.com,1999:blog-6307296850739835065.post-41935998828093005172008-10-08T14:58:00.004+02:002010-03-10T16:35:14.708+01:00Dotnetnuke site constantly to recreate the domain application: "The AppDomain shut down because of the hosting environment."I've made a site using CMS DotNetNuke. On my developing machine it worked very good. After placing It into the hosting I've noticed that pages, especially the first opened very slowly. I looked into site's Event Viewer and see that the application domain recreated several times a minute. There are consistent records:<br /><br /><strong>Application Shutting Down. Shutdown Details: The AppDomain shut down because of the hosting environment.<br /><br />Application Started.</strong><br /><br />Operation of Re-creation of domain application is not fast, and it leads to lower the productivity of the website (slowly loading of pages).<br /><a name='more'></a><br />Since I do not make any changes to the files (including configutation-files) of the web-application, as well as in nested folders of the project, there is the question: why and how to avoid this?<br /><br />Having experience with hostings I know that while struggle for resources, they cofigure session's life to the minimum (sessionState.Timeout). I've wrote the application and checked: Yes, session's life is not more than 10 seconds. I've wrote a letter to the Support to increase it up to 30 minutes. They Did it for me.<br /><br />Now I see that appDomain is not die as often as before. Now it is repeated every 15-20 minutes. Because the site is still no one visits and knowing that application domains can be destroyed due to inactivity, I've created simple windows-service, which make HTTP GET requests to the site every 5 minutes. Result: Application domain almost is not recreate. Problem solved.AKhttp://www.blogger.com/profile/09961221800490275710noreply@blogger.com1