473,394 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Physical path issue... asp.NET 2.0 - VB

gchq
96
I want to use images located outside of the Application - and thought I was being quite smart by including two paths in Global.asax, one for the Server and one for the build machine that VS2005 sits on - then used this bit of code so that it would run on either...

Expand|Select|Wrap|Line Numbers
  1. Private Function ReturnPath()
  2.         Dim vImagePath As String
  3.         Dim vPath As New Uri(Request.Url.ToString)
  4.         Dim vPathString As String = Left(vPath.Authority, 9)
  5.         If vPathString = "localhost" Then
  6.             vImagePath = gFilePath.gFilePathLocal
  7.         Else
  8.             vImagePath = gFilePath.gFilePathServer
  9.  
  10.         End If
  11.         Return vImagePath
  12.  
  13.     End Function
  14.  

Now I must be really missing something here, because I assumed that the path would always be relative to the machine it was being run on, so that on the server it would be C:\Somefolder and on my workstation it would map to K:\Somefolder... But no!! If I load the app onto the server and open it in a browser, it's still wanting the path from my local machine.. So, how do I map to a file outside of the App so that the server locates it, not the local machine? Talk about confuzzed....
Jan 18 '08 #1
6 2027
Plater
7,872 Expert 4TB
Have you debugged to see if your other IF condition is ever met?
Jan 18 '08 #2
gchq
96
Hi Plater

Indeed the other condition is being met and that is the whole problem! I've just unearthed a revelation - I've been writing this stuff since the early days of (classic) asp and only now realised that if you put in a physical path it will map to the physical path of the client machine NOT the server...

So the question is - I guess - is there any method to map to a directory that is not only outside of the app, but also outside of InetPub?

I would assume the only way would be to map a virtual directory from IIS first and then find a method although I have a feeling that .NET security will have an issue with even that....
Jan 18 '08 #3
Plater
7,872 Expert 4TB
Well you could code a "serve up" page (for lack of a better term)
I use it to serve up PDF files.
I have a directory on Computer A where a lot of company documents are kept.
ComputerB has a webserver for our use. I use an intermediate page (and a little more, but don't worry about that) to acces the files on ComputerA without mapping a virtual directory.

So I would have say:
http://ComputerB/PDFServe.aspx?ProductGuidelines.pdf

And PDFServe.aspx looks to see if that file exists, if it does, it clears out the Response (Response.Clear() ) and then sets the contenttype to that of a PDF and sends the file bytes down.

Employee's here may have no idea where these documents are physically stored, nor have access to them, beyond what I provide in the webpage functionality.

You can do the same for images, or anything you want. Using backend code, you are not bound to the locale created by the web application under the inetpub directory.
Jan 18 '08 #4
gchq
96
So how does 'PDFServe.aspx' on ComputerB access files on Computer A?

I can't quite figure out the dynamics of once the page gets the Request.QueryString (for ProductGuidlines.pdf) how it aquires the file...

The other issue is.once the Directory is located it has to load all the file details into a JavaScript array

Expand|Select|Wrap|Line Numbers
  1.  
  2. ....  "var fadeimages=new Array(); " & _
  3.         "while (i <=" & IndexMax & ") { " & _
  4.         "vNext=(vImage+i); " & _
  5.         "if((vNext >= 10)) { " & _
  6.         "NextPic= target02 + vNext; } " & _
  7.         "else if((vNext > 99)) { " & _
  8.         "NextPic = target03 + vNext; } " & _
  9.         "else if((vNext <= 9)) { " & _
  10.         "NextPic = target01 + vNext; }" & _
  11.         "fadeimages[+i]=['" & vPath & Folder & "/" & FileStart & "' + NextPic + '.jpg', '', '']; " & _
  12.         "i = i+1; " & _ ......
  13.  
Jan 18 '08 #5
Plater
7,872 Expert 4TB
In my page_load() event for the serve up page:
Expand|Select|Wrap|Line Numbers
  1. string getfile = ""; 
  2. try
  3. {
  4.    getfile = @"\\ComputerA\pdfs\";
  5.    //add in the file name you want, i.e.:
  6.    // getfile+="SomePDF.pdf";
  7.    if ((!(new System.IO.FileInfo(getfile).Exists)))
  8.    {
  9.       ReportError("The system could not find the requested file for SiteID: " + siteid);
  10.    }
  11.    else
  12.    {
  13.       Response.Clear();
  14.       Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
  15.       Response.ContentType = "Application/PDF";
  16.       Response.WriteFile(getfile);
  17.       Response.End();
  18.    }
  19. }
  20. catch (Exception ee)
  21. {
  22.    if (ee.Message.ToLower().StartsWith("thread was being aborted"))
  23.    {//ignore, should probably catch ThreadAbortException
  24.    }
  25.    else
  26.    {
  27.       ReportError("An error has occured: '" + ee.Message + "' ");
  28.    }
  29. }
  30.  
You should be able to get some idea from that.


Then when you link, instead of doing say this:
Expand|Select|Wrap|Line Numbers
  1. <img src="/images/myimage.jpg" alt="" />
  2.  
You would say:
Expand|Select|Wrap|Line Numbers
  1. <img src="/ServeImage.aspx?Image=myimage.jpg" alt="" />
  2.  
Jan 18 '08 #6
gchq
96
Had to scratch my head regarding the server mapping for a bit. but with:-

Expand|Select|Wrap|Line Numbers
  1.  
  2. GetFile = "\\Interclaims1\InterclaimsC\backup\sk\002\01.jpg"
  3.  
  4.  
It worked a treat! Thank you so much!

I have another issue that this might really help with - I have web apps that produce pdf files on the fly and setting up new templates and installing them on each app looked like a nightmare - with this concept I should be able to have just one template (per item) and instead of :-

Expand|Select|Wrap|Line Numbers
  1.  
  2.  rtnInput = TK.OpenInputFile(Server.MapPath("PDFInput\nucs-4072.pdf"))
  3.  
  4.  
I could just reference the one storage place for the pdf template - even offer differing templates based on database selection! Now I'm off.....

Thanks again
Jan 18 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Simon | last post by:
I wonder if someone can help with this - I 'm creating an IISVirtualDirectory, and setting its Path property to the physical path I want to reference. This works fine when I have a standard file...
1
by: Michiel Schaeverbeke | last post by:
Hi, I'm trying to reach an xml file from within a web application. The file is physically on a different server. When I try to reach it using \\servername\path\ style, I get the error...
2
by: Sakharam | last post by:
Hi All, I am developing a scheduler object for my web application. I am starting new thread on Application_Start event. Everything works fine except following issue. I am using following...
0
by: DagoFlores | last post by:
Hi, Im trying to get programmaticly the physical path of each directory displayed on IIS Console. If the SchemaClassName is "IIsWebVirtualDir" then I can get it (i.e.: "C:\..."). Trying with...
1
by: Raed Sawalha | last post by:
I have a problem in getting asp.net application physical path in global.ascx static function in my global.ascx i have a static function : first i tried to get the physical path by refelection...
9
by: dgk | last post by:
Is there some built in way to know whether a physical folder path is 'My Documents" for a specific user? I can always use xxx.StartsWith to compare it to the enumeration returned by the Personal...
7
by: E | last post by:
I have encountered a very strange problem that is hard to describe, but hope someone has run across it. I have a form that shows a number of columns from a single table in the upper portion of...
4
by: =?Utf-8?B?SmVmZiBCZWVt?= | last post by:
Best way I can think to describe this is through an example. I have a virtual directory, let's call it "MyVirtualDirectory" that maps to \\MyServer\Shared. I have a path that is...
5
by: marss | last post by:
Server.MapPath("~/page.aspx") returns the physical file path based on the specified virtual path. Is there any reverse method to get the virtual path based on the physical path (both pathes belong...
0
by: Ahmedhussain | last post by:
Hi everyone, I am totally new to IIS. I somehow configured IIS and now whenever I try to add a website, on testing it gives me the error of authorization, i.e. "Cannot verify access to path :...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.