Solved

Severside text file access

Posted on 2004-04-07
10
219 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
ID: 10782353
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
ID: 10782359
BTW I personally prefer CGI exe instead of ISAPI dll.
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10782369
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
ID: 10782633
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
ID: 10798050
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10806038
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
ID: 10807065
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
ID: 10807534
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
ID: 10807563
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
ID: 10807579
Yeah, that's it.

Thanks for your points,
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert Jpg /PNG To GIF 5 118
Virtuailstring tree add node to another virtuailstring tree list 4 104
Performance of SQL statement 37 97
PHP preg_replace code convert to Delphi 14 32
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

911 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

21 Experts available now in Live!

Get 1:1 Help Now