Solved

Severside text file access

Posted on 2004-04-07
10
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using idhttp to login to instagram 2 119
Downloading email attachments 2 85
control image tags in a string ? 12 153
Delphi and Access based Enumeration 9 78
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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