Archive for the ‘Development’ Category
If you have been working with SharePoint designer for a while you must have come across this error at least once while checking in a file.
According to Randy Drisgill this error is caused due to SPD’s cache and clearing the cache resolves the issue. You can manually delete the files from those folders or you can just run this batch (.bat) file.
cd "%APPDATA%\Microsoft\Web Server Extensions\Cache" del *.web /S /Q "%APPDATA%\Microsoft\Web Server Extensions\Cache" cd "%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache\" rmdir /S /Q "%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache\." mkdir "%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache" dir "%APPDATA%\Microsoft\Web Server Extensions\Cache" dir "%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache" pause
One of the many .NET open-source projects that don’t get the attention they deserve is MsSqlSpatial. This project provides spatial extensions to SQL Server 2005 – meaning you can perform various spatial calculations right in your T-SQL queries! Cool eh? But, this project lacks documentation which is a problem for us developers. I’m sure they are working their ass off to make one but in the mean time we have to play around with the code to understand its inner workings.
Since Google Maps is very popular among developers, and my personal favorite, I thought why not give out some tips.
Most of their functions, require this as a parameter. If your GIS application uses Google Maps then you should use 4326.
Convert a Point on the map from a Well-Known-Text(WKT) format to a Well-Known-Binary Format:
SELECT ST.PointFromText('POINT(-87.6673250 41.9489650)', 4326)
The Point should be of the format POINT( longitude latitude ).
Polygon to text:
SELECT [Bloggernate].[ST].[PolygonFromText] ( 'POLYGON((-87.71956443786621 41.96727630029047,
-87.71956443786621 41.96727630029047))' ,4326)
The polygon must be a closed one otherwise you’ll receive an exception.
Check if a polygon contains a specified point:
SELECT [ST].[Contains] (YOUR_WKB_POLYGON, YOUR_WKB_POINT)
I hope this provides a good starting point for those daring to step into the unknown
The first time I used Firebug (back then there was no IE8 Dev toolbar) I fell in love with it and as a Web Developer, life without it is unimaginable. This excellent article by Chris Brandsma tells you why its so. Check it out here.
My current project requires me to download huge amounts of data from a remote server in the form of XML and save them to our local database. Lets see if we can do this using just one simple T-SQL stored procedure. Lets first create our table. For the purpose of this demonstration I will use a simple schema with the following signature
1: CREATE TABLE [dbo].[Employee](
2: [EmployeeID] [int] IDENTITY(1,1) NOT NULL,
3: [Name] [nvarchar](50) NOT NULL,
4: [Gender] [varchar](1) NOT NULL,
5: [DateOfBirth] [datetime] NOT NULL,
6: CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED
8: [EmployeeID] ASC
9: )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
10: ) ON [PRIMARY]
Next, we need to create the stored procedure that will do the batch insert for us.
CREATE PROCEDURE [dbo].[spr_Employee_ProcessXmlData](@employees xml) AS BEGIN DECLARE @TempTable TABLE ( [Name] [nvarchar](50), [Gender] [varchar](1), [DateOfBirth] [datetime] ); -- Populate the Temporary table from the XML INSERT INTO @TempTable (Name, Gender, DateOfBirth) SELECT ParamValues.Data.value('Name','nvarchar(50)'), ParamValues.Data.value('Gender','varchar(1)'), ParamValues.Data.value('DateOfBirth','datetime') FROM @employees.nodes('NewDataSet/Employee') as ParamValues(Data); INSERT INTO Employee(Name, Gender, DateOfBirth) SELECT T.* FROM @TempTable T WHERE T.Name NOT IN (SELECT Name FROM Employee) END
I won’t go into details about the XML programming – this great article are among several others that provide a good start for those unfamiliar with this feature of T-SQL. The stored procedure first creates a temporary in-memory table which will hold the data from the XML. Each node is read from the XML and mapped to the appropriate column of the temporary table. The temporary table is merely used to prevent duplicate data from being inserted into our actual table. If you are certain that your XML will never contain redundant data, then you can skip this step and directly insert the data to the Employee table.
We are now ready to perform batch inserts! The following SQL script demonstrates how.
EXEC [dbo].[spr_Employee_ProcessXmlData] @employees = '<NewDataSet> <Employee> <Name>Raihan Iqbal</Name> <Gender>M</Gender> <DateOfBirth>11-05-1983</DateOfBirth> </Employee> <Employee> <Name>John Doe</Name> <Gender>M</Gender> <DateOfBirth>10-05-1972</DateOfBirth> </Employee> </NewDataSet>'
It is needless to say that we can generate the XML and execute the stored procedure using any .NET language.
In many of my projects I have had to generate non-binary trees using information from the database and then display them in a “tree-like” structure as shown below.
My algorithm is very simple and it makes use of Dan Vanderboom’s excellent Generic Tree Collection but frankly I’m not satisfied with certain aspects of my algorithm. The main issue – the data can never be retrieved in the same order as shown above from the database.
Now that we have a collection ready, we can generate the tree structure
Finally, I add the items to my drop-down control by calling
Let’s have a look at the function
I know I could have used LINQ but many of my projects are running in .NET 2.0 so I had to go old-school! I’m looking forward to your valuable comments as to how YOU would do this and why your solution is more efficient than mine.
I’m pretty much sure many of you have encountered this error if you have been using Code blocks inside your ASP.NET master pages for example,
1: <img src='<%= Page.ResolveUrl("~/image/top-mnu-agents.jpg") %>' alt="Agents" name="agents"
2: width="109" height="42" border="0" id="agents" /></a>
1: function PreloadImages()
3: /*MM_preloadImages('<%= Page.ResolveUrl("~/image/top-mnu-property.jpg") %>',
4: '<%= Page.ResolveUrl("~/image/top-mnu-agents.jpg") %>',
5: '<%= Page.ResolveUrl("~/image/top-mnu-company.jpg") %>',
6: '<%= Page.ResolveUrl("~/image/top-mnu-contact.jpg") %>');*/
Is this going to work? Make a guess! No, its not! Bump! Even though the code block is inside a comment block! How’s that! If you are curious why, ask the guys at Microsoft
I’m sure there are plenty of similar topics out there but this is my two cents. Lets say you have the following code in your ASP.NET page:
1 Upload a File: <asp:FileUpload ID="pictureUpload" runat="server" /><br />
2 <asp:Button ID="btnUpload" runat="server" Text="Upload" OnCommand="handle_ButtonClick" CommandName="Upload" />
Let’s look at the event handler code that uploads the image to the server and resizes it.
1 protected void handle_ButtonClick(object sender, CommandEventArgs e)
3 if (e.CommandName == "Upload")
5 if (pictureUpload.HasFile)
7 string FilePath = HttpContext.Current.Server.MapPath(PATH_FILESFOLDER) + pictureUpload.FileName;
9 ResizeImageAndSave(FilePath, 90);
14 public void ResizeImageAndSave(string FilePath, int Width)
16 Bitmap loBMP = new Bitmap(FilePath);
17 ImageFormat loFormat = loBMP.RawFormat;
19 //*** If the image is smaller than a thumbnail just return it
20 if (loBMP.Width < Width) return;
22 decimal lnRatio = Convert.ToDecimal(Width) / loBMP.Width;
23 int lnNewWidth = Width;
24 int lnNewHeight = Convert.ToInt32(loBMP.Height * lnRatio);
26 Bitmap bmpOut = new Bitmap(lnNewWidth, lnNewHeight);
27 Graphics g = Graphics.FromImage(bmpOut);
28 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
29 g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
30 g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
32 //Dispose old BMP object
The code is pretty obvious – save the file to the specified path, resize the image, dispose the old image and finally save the new image.
Sometimes developers need to simulate network delay during development and testing for various reasons. Sloppy is a tool that does just that. You will need the latest java runtime installed for it to work. Just go the link above and follow the instructions.