How to Publish Custom files (PDF, EXCEL, WORD etc.) using VS2010/VS2008?

Publishing of the Project or Application is required for deploying to Test or Production instance. Usually whenever we publish the WebProject using publish option of (Visual Studio), it will publish only the known type of files and folder to Published location. Like Style, Script, Images, MastePages and any other folder which contain known type of files.

Known type of files are .master,.aspx, .ascx,.asmx,.svc, .js,.css, .png,.bmp etc.

But if we have files like .pdf, .xls, .txt etc. then it will be not published automatically. In that case we need to manually create folder and copy the files to respective folder. Since we may not rember always do this while publishing the code for Production or Test instance. Therefore to avoid such situation you can follow below approach.

Consider the below example

I have created one project named TempProject which contain some files as shown below.

pic-1.PNG

Now when I publish it, it will publish below list of files and folder

pic-2.png

In the above list the PDF folder files (GuideBook.pdf) has not been published, to publish this file we need to modify the project file of TempProject (TempProject.csproj). Refer the below step to do the same

  • Open the project file in Notepad
  • Go to <ItemGroup> option
  • Add new group as <Content Include="Pdf\GuideBook.pdf" />
  • Save the project file

Please refer below

pic-3.png

Now after this changes when I publish again, I will able to see the PDF folder and files

pic-4.png

Note: Empty folder will be not published. So if you want to publish a folder which will be not containing any files but later you will saved files to that folder by using your application, in that scenario you can create a temp or dummy files inside that folder.

Ebook Download
View all
Learn
View all