Want to Distribute PDF file with my Visual Basic Project during Deploying

☆樱花仙子☆ 提交于 2019-12-01 13:09:22

问题


I have Visual Basic (Visual Studio Professional Edition, .NetFrameWork 4.0) I want to include and Call PDF with my Button_Click_Event I include MyPDF.pdf in Resources and after that I follow the link and call as:

Process.Start("LinkTo\MyPDF.pdf")

but this is Ok and works, as this in my own PC, but when I install this in another PC (or I displace the PDF from the link as specified) so it fails to open the MyPDF.pdf

So My Question as What I did that during installation also MyPDF.pdf also install on user computer and which code I use for this?

Thanks in advance :)


回答1:


Firstly, press on the pdf file in the solutions explorer. Propeties of the file should be as following:

Build Action: Content 
Copy to output directory: Copy always

The path to the file in users computer will be Application.StartupPath & "\Resources\MyPDF.pdf"

Not sure I did not forget something, so tell me if it works :)


EDIT: I see a lot of people are having trouble with this so here is the simplest way I know to deploy a file together with .net program in visual studio:

  1. Drag and drop the file to the solutions explorer
  2. Press on the file in the solutions explorer and modify it's propeties to:

    Build Action: Content;
    Copy to output directory: Copy always

  3. The path to the file to be used in code will be Application.StartupPath & "\filename.txt"
I think there is a way to do it without Application.StartupPath, which may cause problems somehow, but i don't know how


回答2:


Wah!!! Great And finally I am able to open any file in other machine
I did this by ordinary methods so I was failed I am going to explain for those who wana learn:
1)= I add PDF file by clicking on properties in solution explorer, then I select Resources, In Resources I add "Add Existing Item" So PDF is added to my project in "Resources" folder

2)= After that I click on PDF in solution explorer and Change Build Action to : Content (even none also works) and Copy to output directory to: Copy always (As suggested by you :))

3)= So whats wrong, actually compiler make folder outside bin folder and we all paste only Release folder(when we deploying, I actually do this lol), so i just cut(Ctrl+X) Resource folder and paste inside in Release folder, and call by this code:

Process.Start("Resources\MyPDF.pdf")

I am sure if we copy the PDF file directly in Release folder so this will also work with this code:

Process.Start("MyPDF.pdf")

I am sure this will help for those who are in search of this!
Thank you guys who help me. Jazakallah



来源:https://stackoverflow.com/questions/15926111/want-to-distribute-pdf-file-with-my-visual-basic-project-during-deploying

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!