Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4058204
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:02:59+00:00 2026-05-20T15:02:59+00:00

I have written a controller action that checks for the existence of a PDF

  • 0

I have written a controller action that checks for the existence of a PDF file and then returns the file (if found) to the browser as a download.

public ActionResult GetMyFile(string path)
{
    if (String.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException("filename"); }

    string downloadFileName = System.IO.Path.GetFileName(path);
    // The worker process identity must have read access in both the file system and share
    // otherwise this always returns false.
    if (System.IO.File.Exists(path)) 
    {
        FilePathResult result = 
            File(path, System.Net.Mime.MediaTypeNames.Application.Pdf, downloadFileName);
        return result;
    }

    return Content("no file", "text-plain");
}

Everything works fine, if the path parameter refers to a local path on disk (e.g. "D:\MyFolder\MyFile.pdf"), but when the path is a UNC path, the PDF is returned, but rendered as plain text in the browser.

Here’s a snippet of what this looks like…

%PDF-1.3
1 0 obj
<<
/Length 1409
/Filter /FlateDecode
>
stream
X���I�%&/m�{J�J��t��$ؐ@�������iG#)�*��eVe]f@�흼��{����{����;�N’���?\fdl��J�ɞ!���?~|?”~Q�����”�Iw�Ow����:O��,��’?���dg|g/����P��t�Ӄ����:}��Ç������to���}�7��q��/�>O�>�_����9!�g������Y���|�{�p�?�������?����ܿO����s�>���’ڜH������;��D��>�� ���?��?J��t�m����t�C���O�(i�����H������~H��7JLǎ��K�%ͧ������T1�������S���=��.F.#�׷ww�����z�wǟҴ~���x�~���Px�������|3�j����c��)f1��O�1�4�����b�qN̔>������跟j�jB?��݃ ����c��.���ڀ�^ofq�,�Pp���g��=Oo�
��7�}��פ�> ��m)}�~�W!�w��Q�0SR�3���2-���&-��Fhy�S�]���HiyF_���
�4�;Q��l�f��|]>ۍ�hc��C��64���|L�4�9Pξ�{#-�?��|���=1Tl��O�����݂6�����a֡�.fe΀:�����/��1��#�{���������?��|v��}�4�}Cw��!�
���&z�v��4�����Uj0
�&���-��������x�i�ģ����|=�9LnI7�&+�gʃ�;��U� m��
M��.�ޏ�D�QvT��ϯ���f���(��������0��������{_������ui�Rid�6���u��a��x"��m��{�o$����
����.���{@xu�8ӮR�����Ύ�r��{�m��$��O ��v����=�������X!~,E,�P����mf�2%9{��m����֍b���8���ñ��:
�PE��O<�e~jƄ�ߨ���?�Z�������"�Ǟ:����D��N�ߌ����PL��0��U����F4 g�oPW�Ml��#"�~ラ���_�����뾯���?���mGo�������=�bwGr/��b���?t3(�����t��=[\��O+���c������res����u��0�,G��f��̲qO��\�S��7��q̘�܀,.����Wn$��w�M%�����2ymd�I<͑U��eV�A-|�DڵDz�à�/]��J�|�ݾ’��$.\W��R�>���l|%�a�gj���0|{�R�c�������!�lwv?S��^S
E����z��3�����hr�{��R”C�݅o��Ac�*T��Q��IE�6XP5ˮ�j4k��v�
D��-��
endstream

Any thoughts as to why this might be happening?

My environment is an ASP.NET MVC 3 application running in IIS on Windows 7.
The client is Internet Explorer 9 RC running on the same machine.

The UNC path is a shared folder on the same machine as the web server, and is the same physical location used in the “local path test” (which succeeds).

For permissions I have ensured that the worker process identity for my application pool has Read permissions in both the file system and through the share.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:03:00+00:00Added an answer on May 20, 2026 at 3:03 pm

    I figured it out.

    Changing the final return statement from:

    return Content("no file", "text-plain");
    

    to

    return null;
    

    Seems to have fixed the problem. Although I’m not sure as to why that is. I would think that if the first return (in the if block) was executed, then the final one would have never come into the picture.

    I’m happy to accept someone else’s answer if they can explain why that is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble creating a Catalyst action that would match a single file in
I have override for controller that checks if certain session data exists. This data
I have an action that basically does this: public ViewResult Save(Foo postedFoo) { Foo
I have an action from a controller that provides a result variable via $this->set('found_products',
I have written VHDL code for VGA controller for spartan 3E board. The code
I have written a function that sorts a big scale of data. To test
I have written a function that extract the domain from hostname. e.g. www.domain.com ->
I have written a very simple CTE expression that retrieves a list of all
I have a controller action and I want it to be executed after any
I have written an ASP.NET MVC application that runs inside an IFrame. When one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.