Download AutoCAD’s .dwt files from SharePoint Document Library

Recently I came across an issue with one of the customers. They are using a lots of AutoCAD files which are with DWT extension and are uploaded to a SharePoint’s document library.

But when they are trying to download the .dwt files, it is failing always with error 403 (The Website declined to show this page)

Now what are .dwt files?

- DWT file extension is used by AutoCAD to save its templates.
- DWT file extension is used by FrontPage/SharePoint Designer to save

“Dynamic Web Templates”
The questions comes up is that customer is using AutoCAD files but why SharePoint is throwing a 403. I started investigating and thought, it could be a corrupt AutoCAD file, but after using 3-4 different files, still it was thrown 403.

Then I created a simple plain text file and renamed it to .dwt and uploaded to SharePoint. Now when I tried to download it, still the same issue and SharePoint threw a 403 error again.

This got me digging into SharePoint and consulting my internal resources which turned up that SharePoint has blocked downloading of any file with .DWT extension. This was done to not allow people to download FrontPage/SharePoint Designer’s “Dynamic Web Templates”, which also incidentally have a .DWT extension.

Now my customer was having a lots of .DWT files up in SharePoint and now wanted to download them using their custom application. After consulting my internal resources, finally I got that using FPRPC, we should be able to download the .dwt files as the code path of FPRPC is different within SharePoint.

This whole thing led me to create a simple console application which used FPRPC to download a .dwt file to my local disk.

    1: namespace FPRPCDownloadFile
    2: {
    3:     class Program
    4:     {
    5:         static void Main(string[] args)
    6:         {
    8:         //Place where we want to put the file
    9:             string filepath = @"C:\DestLoc.dwt";
   11:         // Point to Author.dll
   12:             string sURI = "http://MySharePoint/_vti_bin/_vti_aut/author.dll";
   14:         // This is the FPRPC method we use
   15:             string sMethod = "get document:";
   17:         // This is the actual FPRPC command that we give
   18:             string sRPC = String.Format("method={0}&service_name=/&document_name=docs/testFile.dwt", sMethod);
   20:         // We need to convert the whole FPRPC query/command to be converted to BYTES before sending over the wire
   21:             byte[] bRPC = System.Text.Encoding.UTF8.GetBytes(sRPC);
   24:         // We will be using WebClient to issue the command and fetch the file
   25:             WebClient wc = new WebClient();
   26:             wc.Credentials = System.Net.CredentialCache.DefaultCredentials;
   28:         // Adding the required headers for FPRPC
   29:         wc.Headers.Add("Content-Type", "application/x-vermeer-urlencoded");
   30:             wc.Headers.Add("X-Vermeer-Content-Type", "application/x-www-form-urlencoded");
   32:         // Finally send the request to the server and get output as byte array
   33:             byte[] sResponse = wc.UploadData(sURI, bRPC);
   35:         // Convert this byte array to string as we want to strip off the Vermeer/FPRPC header and get the actual file content
   36:             string returnStr = System.Text.Encoding.UTF8.GetString(sResponse);
   38:         // Find where does the header ends and get the actual byte array of our file
   39:             long iEnd = returnStr.IndexOf("</html>") + 8;
   40:             long length = sResponse.Length - iEnd;
   41:             byte[] contents = new byte[length];
   42:             Array.Copy(sResponse, iEnd, contents, 0, length);
   45:         // Now write the actual file's byte array to the local file specified
   46:             using (StreamWriter sw = new StreamWriter(filepath, false))
   47:             {
   48:                 using (BinaryWriter binWriter = new BinaryWriter(sw.BaseStream))
   49:                 {
   50:                     binWriter.Write(contents);
   51:                     binWriter.Flush();
   52:                     sw.Flush();
   53:                     sw.Close();
   54:                 }
   55:             }
   57:             Console.WriteLine("Created file: " + filepath);
   58:         }
   59:     }
   60: }

Hope this helps anyone else also having trouble to download the AutoCAD’s .dwt files.


Happy Coding…