Solved

Severside text file access

Posted on 2004-04-07
10
218 Views
Last Modified: 2010-04-05
Hi

     I'm currently planning a server side project in which I would need to access txt files on the server, however I am unsure quite how to go about this, and so have a few questions:

    Is it possible to write to the txt file when it’s on the server where would it be best to place them? Do I need to change the    
   Files access rights?
    If so what would the path to a text file be? Obviously not C:\mytextfile.txt would it be something like    
      www.mysite.com/mytextfile.txt??
    How do I cope with simultaneous access requests, I really have no idea...
    Anything else I should consider?

  I would be happy building the project either as a Dll or a CGI exe in your expert opinions would be easier in light of the above, especially dealing with simultaneous access requests

Thanks in advance

David
0
Comment
Question by:DavidBirch2dotCom
  • 5
  • 3
  • 2
10 Comments
 
LVL 17

Expert Comment

by:geobul
Comment Utility
Hi,

If your app is an ISAPI or CGI app on a server (obviously accessed via Internet browser) and the text file is on the same server then your app accesses the file as a local file, i.e. c:\mytextfile.txt.

If the file is on another computer in the same LAN where the server is then the folder (where the file is in) should be shared and your app can access it using a mapped drive or UNC name (\\SecondServer\SharedFolder\mytextfile.txt).

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
Comment Utility
BTW I personally prefer CGI exe instead of ISAPI dll.
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
Comment Utility
Thanks,

I would be deploying the project onto a shared webserver for use on my website, so I doubt I would be able to access the C drive

Would I be able to write to the text file if it was at www.mysite.com/mytextfile.txt?

How would I cope with simultaneous access requests? Does CGI exe make this easier?

David
0
 
LVL 17

Expert Comment

by:geobul
Comment Utility
Does your CGI app see any local file system? Can you use a static html page (a file stored somewhere on the server) and send that page as a response from your CGI?
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
Comment Utility
Yes im testing the app on PWS on my computer, it will access the file if i give the right address eg C:\Mytxt.txt but not if i go
Webserver/Scripts/Mytxt.txt  ??? am i giving the address wrong? what should it be? i very much doubt i would be able to access the C drive on the server so I really need an answer.

David
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 7

Author Comment

by:DavidBirch2dotCom
Comment Utility
ok ive found some code that might do what i want, i found this on the following site http://www.nickhodges.com/Delphi/Articles/DL180/dl180.htm#HTML%20From%20an%20Existing%20File

HTML From an Existing File
 This next example is very similar to the first, but instead of creating the HTML on the fly, theTPageProducer uses an existing HTM file to establish the basis for the response. TheTPageProducer.HTMLFile property is set to the specified file, and then the OnHTMLTag event occurs to replace a user-defined tag with the full path of the module name of the application.
In order to assure that the file can be found on any system that might run the app, a call is made to the Windows API function GetModuleFileName, which fills the specified buffer with the path to the calling module. This call is made within the little known SetString procedure which makes a string out of a PChar variable. The result is used to set theTPageProducer.HTMLFile property:
procedure TWebModule1.WebModule1Create(Sender: TObject);
var
  Path: array[0..MAX_PATH - 1] of Char;
  PathStr: string;
begin
  SetString(PathStr, Path, GetModuleFileName(HInstance, Path,        
       SizeOf(Path)));
  PageProducer1.HTMLFile := ExtractFilePath(PathStr) + 'appname.htm';
end;
Once the HTMLFile property has been set, the code is almost identical to the previous example:
procedure TWebModule1.WebModule1Actions0Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled:
Boolean);
begin
     {HTMLFile property was set in OnCreate of the datamodule}
     Response.Content := PageProducer1.Content;
     Handled := True;
end;


procedure TWebModule1.PageProducer1HTMLTag(Sender: TObject; Tag:
TTag;
  const TagString: String; TagParams: TStrings; var ReplaceText:
String);
var
  Path: array[0..MAX_PATH - 1] of Char;
  PathStr: string;
begin
     case Tag of
       tgCustom:
         begin
           if CompareStr(TagString, 'AppName') = 0 then
           begin
                SetString(PathStr, Path, GetModuleFileName(HInstance,
                                Path, SizeOf(Path)));
                ReplaceText := PathStr;
           end;
         end;
     end;
end;
 

 however there are some problems with it- mainly that Delphi doesnt seem to know what the MAX_PATH var isnt recognised , and neither is the GetModuleFileName !!!! what am i missing??? do i need to use a special unit?

David
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
Comment Utility
ok ive fixed the above

I’m not trying to access anything outside of the CGI bin, however I just didn’t know how to access the stuff in the CGI bin - now I do :)

However I am still trying to figure out how I could cope with multiple simultaneous requests for the same file.... any ideas?

Thanks

David
0
 
LVL 1

Accepted Solution

by:
tanghz earned 125 total points
Comment Utility
Hi,
Normally just use one CriticalSection var since you just have one block of code need independently processed.
unless you want another job to do in this way then you may need a different CS.

Just have a try, you will see it.


Good luck
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
Comment Utility
ok i see what u mean , like if i was using 2 different text files then i could use 2 different CriticalSection's  - 1 4 each :)

thannks :)

DAvid
0
 
LVL 1

Expert Comment

by:tanghz
Comment Utility
Yeah, that's it.

Thanks for your points,
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now